更新时间:2021-07-22 12:23:00
ylbtech- .NET-Basic:C#中的值类型与引用类型的区别 |
C#中的值类型(value type)与引用类型(reference type)的区别
1.A,相关概念返回顶部 |
1.B,测试源代码返回顶部 |
using System; namespace ConsoleApplication1 { class RefClass { public int Value = 0; } /// <summary> /// ylb:C#中的值类型与引用类型的区别 /// </summary> class Program { static void Main(string[] args) { int val1 = 0; int val2 = val1; val2 = 123; RefClass ref1 = new RefClass(); RefClass ref2 = ref1; ref2.Value = 123; //主要只修改了对象 ref2 中的值 Console.WriteLine("Values:{0},{1}",val1,val2); Console.WriteLine("Refs:{0},{1}", ref1.Value, ref2.Value); } } }
//ExecutionResult
Values:0,123 Refs:123,123 请按任意键继续. . .
1.C,资源下载返回顶部 |