类和结构
2012-04-26 22:19 精诚所至 金石为开 阅读(274) 评论(0) 编辑 收藏 举报类和结构类似。
using System; namespace a { class MyClass { public int val; } struct myStruct { public int val; } class Program { static void Main(string[] args) { MyClass objectA=new MyClass(); MyClass objectB=objectA; objectA.val=10; objectB.val=20; myStruct structA=new myStruct(); myStruct structB=structA; structA.val=30; structB.val=40; Console.WriteLine("objectA.val={0}",objectA.val); Console.WriteLine("objectB.val={0}",objectB.val); Console.WriteLine("structA.val={0}",structA.val); Console.WriteLine("structB.val={0}",structB.val); Console.ReadKey(); } } }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)