1、准备
struct Str
{
public int i;
}
class Cla
{
public int i;
}
2、赋值
Str str = new Str();
str.i = 10;
Cla cla = new Cla();
cla.i = 10;
分类:
运算A
static void F(Str str)
{
str.i = 100;
}
static void F(Cla cla)
{
cla.i = 100;
}
结果A
F(str);
Console.WriteLine(str.i);//结果10
F(cla);
Console.WriteLine( cla.i);//结果100
运算B
static void F(ref Str str)
{
str.i = 100;
}
static void F(ref Cla cla)
{
cla.i = 100;
}
结果B
F(ref str);
Console.WriteLine(str.i);//结果100
F(ref cla);
Console.WriteLine( cla.i);//结果100
运算C
static void F(Str str)
{
str=new Str();
str.i = 100;
}
static void F(Cla cla)
{
cla=new Cla();
cla.i = 100;
}
结果C
F(str);
Console.WriteLine(str.i);//结果10
F(cla);
Console.WriteLine( cla.i);//结果10
运算D
static void F(ref Str str)
{
str=new Str();
str.i = 100;
}
static void F(ref Cla cla)
{
cla=new Cla();
cla.i = 100;
}
结果D
F(ref str);
Console.WriteLine(str.i);//结果100
F(ref cla);
Console.WriteLine( cla.i);//结果100