A new colleague asked me today. NET, what is the difference between a method signature with out, a ref, and a common method signature? I think we can illustrate some key points from the following examples.
One, ref/out modifier description
The instructions for using the Ref/out modifier are detailed on MSDN with the following address:
HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/T3C3BFHX (vs.80). aspx.
Second, through the IL Code observation ref/out decorated method signature (in the case of value types)
1. Sample code:
using System;
namespace ConsoleMain
{
class Program
{
static void Main()
{
Int32 p ;
TestRef(out p); //①
//TestRef(ref p) //②
TestRef(p); //③
Console.ReadKey();
}
static void TestRef(Int32 para) //④
{
para = 1;
}
static void TestRef(out Int32 para) //⑤
{
para = 2;
}
/*static void TestRef(ref Int32 para) //⑥
{
Para3 = 3;
} */
}
}