110,539
社区成员
发帖
与我相关
我的任务
分享
class Entry
{
public static void Main()
{
int a = 1;
Set( ref a );
}
public static void Set( ref int b )
{
b = 2;
}
}
C语言
void Set( int *b )
{
*b = 2;
}
int main( void )
{
int a = 1;
Set( &a ); //&相当于C#中的ref
}
[/quote]
对的对的,完全正确。class Entry
{
public static void Main()
{
int a = 1;
Set( ref a );
}
public static void Set( ref int b )
{
b = 2;
}
}
C语言
void Set( int *b )
{
*b = 2;
}
int main( void )
{
int a = 1;
Set( &a ); //&相当于C#中的ref
}
public class ClassA
{
public string _strValue = "defaultValue";
}
void RefTest(ClassA param)
{
param._strValue = "Changed";
}
ClassA srcClass = new ClassA();internal void Test()
{
ClassA srcClass = new ClassA();
Console.WriteLine("Before function called : " + srcClass._strValue);
RefTest(srcClass);
Console.WriteLine("After function called: " + srcClass._strValue);
}
void RefTest(ClassA param)
{
ClassA copy_one = (ClassA)param.Clone();
copy_one._strValue = "Changed";
}
public class ClassA:ICloneable
{
public string _strValue = "defaultValue";
#region ICloneable 成员
public object Clone()
{
return this.MemberwiseClone();
}
#endregion
}
int i=10;
Conslole.WriteLine(i);//相当于把i存储的值复制一份给Conslole.WriteLine使用,内存中存在两个10
myType my=new myType();//假设myType是引用类型;
Conslole.WriteLine(my);//这是把my这个引用复制一份给Conslole.WriteLine使用,内存中有两个对myType实例的引用。
加上ref或者out则不会引起参数的复制,传递的是参数地址【值类型引用类型相同】