class Program
{
static void Main(string[] args)
{
double start1=0;
double end1=0;
Test1(start1,end1);
Console.WriteLine("test1:"+start1+"------"+end1);//0---0
double start2 = 0;
double end2 = 0;
Test2(ref start2, ref end2);
Console.WriteLine("test2:" + start2 + "------" + end2);//1000----2000
Console.ReadLine();
}
private static void Test1(double a,double b)
{
a = 1000;
b = 2000;
}
private static void Test2(ref double a,ref double b)
{
a = 1000;
b = 2000;
}
}
C# ref使用
最新推荐文章于 2024-08-04 02:23:11 发布
本文探讨了C#中静态方法与引用类型参数传递的区别。通过实例Test1和Test2展示,当使用`double`类型的静态方法时,变量值不会改变;而引用方法`Test2`中,传入的`ref`关键字使得外部变量被修改。关键实验结果:test1中的start1和end1保持不变,test2则输出1000和2000。
摘要由CSDN通过智能技术生成