Pass by Value

phrase

say it: “PASS by VAL-yoo” /pæs baɪ ˈvælju/

Calling a method with a copy of each argument's value, C#'s default, so changing the parameter doesn't change the caller's variable.

What is Pass by Value in C#?

Pass by Value — C#'s default way of passing an argument: the method gets a copy of its value. The method can change its parameter, and the caller's variable keeps its value.

int georgia = 12;
AddTouchdown(georgia);
Console.WriteLine(georgia);  // 12: the method changed only its copy

void AddTouchdown(int score)
{
    score = score + 6;
}

In a sentence

  • “Without ref, C# uses pass by value, so the method's change to score stays inside the method.”

Level: Apprentice · More C# terms at this level

Updated