If there is similar, it is honored, if reproduced, please specify
C # in the ref and out pass parameter summary, two can be used to pass parameters, ref must be initialized before use, out is not required, as long as the return before the assignment, text nonsense to this, the following direct example
ref example
Class A
{
private string name = String. Empty;
private int count = 0;
...
GetName (ref name,ref count);
Console.Write ("Name:" + name + ", Quantity:" + count);
}
Class B
{
...
The parameter name is 1 pointers to the stack that have a value type of string
The parameter count is a pointer to 1 that points to the value type int in the stack
public bool GetName (ref string Name,ref int count)
{
...
name = "Ching";
Count = 10;
return true;
}
}
Output Result: Name: Ching, Quantity: 10
out example
Class A
{
private string name;
private int count;
...
GetName (ref name,ref count);
Console.Write ("Name:" + name + ", Quantity:" + count);
}
Class B
{
...
public bool GetName (ref string Name,ref int count)
{
...
name = "Ching";
Count = 10;
return true;
}
}
The same output results: Name: Ching, Quantity: 10
To sum up, ref and out in C # have the same effect, just note that ref needs to initialize the value first, out is not required, but to be assigned a value before returning, the above is a simple elaboration, detailed introduction or confusion in the use of the official version of the MSDN manual can be, welcome everyone treatise
Summary of C # ref and out pass parameters