As per https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/method-parameters#params-modifier
When you pass a value type by reference:
A) If the method assigns the parameter to refer to a different object, those changes aren’t visible from the caller.
public int Sq(ref int number)
{
// Assigned a different instance means it address is different from what is passed
number = new int();
number = 10;
return number;
}
But here changes are visible in called
B) If the method modifies the state of the object referred to by the parameter, those changes are visible from the caller.
public int Sq(ref int number)
{
//Modifying number to 10 and this cannot visible in called method
number = 10;
return number;
}
I Understood B but how to prove A. please help me to provide correct code to prove A
haria arava is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.