1 结构是值类型,类是引用类型 2 3 private class mclass 4 { 5 public int val; 6 } 7 8 private struct mstruct 9 { 10 public int val; 11 } 12 13 private static void ClassAndStruct() 14 { 15 mclass mc1 = new mclass(); 16 mclass mc2 = mc1; 17 mstruct ms1 = new mstruct(); 18 mstruct ms2 = ms1; 19 20 mc1.val = 10; 21 mc2.val = 20; 22 ms1.val = 30; 23 ms2.val = 40; 24 25 Console.WriteLine("mc1.val={0}", mc1.val); // 20 26 Console.WriteLine("mc2.val={0}", mc2.val); // 20 27 Console.WriteLine("ms1.val={0}", ms1.val); // 30 28 Console.WriteLine("ms2.val={0}", ms2.val); //4 0 29 } 30