3、ref关键字参数方法:出得来,进得去
{
Myclass mc= new Myclass();
int[] arrint = new int[] { 1, 2, 3 };
mc.Method5("d", 2, 3, 4, 1, 2, 2, 2, 2, 2);
//int i = 10;
//string j = "11";
//mc.Method4(out i, out j);
//Console.WriteLine(i);
//Console.WriteLine(j);
//string i = "10";
//mc.Method3(ref i);
//Console.WriteLine(i);
//int i = 200;
//mc.Method1(i);
//Console.WriteLine(i);
//int[] arrint = new int[] { 1, 2, 3 };
//mc.Method2(arrint);
//foreach (int i in arrint)
//{
// Console.WriteLine(i);
//}
}
}
partial class Myclass
{
//定义值类型的参数
public void Method1(int i)
{
Console.WriteLine(i);
i = 100;
}
//引用类型的参数
public void Method2(int[] arrint)
{
foreach (int i in arrint)
{
Console.WriteLine(i);
}
arrint[0] = 100;
}
//ref作参数
public void Method3(ref string i)
{
Console.WriteLine(i);
i = "100";
}
public void iss(ref string j)
{
Method3(ref j);
}
//out作参数
public void Method4(out int i, out string j)
{
i = 100;
j = "10";
Console.WriteLine(i);
}
//动态参数
public void Method5(string t, params int[] arrint)
{
foreach (int i in arrint)
{
Console.WriteLine(i);
}
//arrint [0]=100;
}
public void Method5(string a, int b)
{
Console.WriteLine("222222");
}
}