本帖最后由 葛杨杨 于 2013-5-27 07:16 编辑
个人觉得下面这串代码中, Age 和 Name 的类型并没有明显的区别, 如何区分哪个是值类型, 哪个是引用类型?- namespace 值类型与引用类型的区别
- {
- class Program
- {
- static void Main(string[] args)
- {
- ReferenceAndValue.Demonstration();
- Console.ReadKey();
- }
- }
- public class stamp
- {
- public string Name { get;set;}
- public int Age{get;set;}
- }
- public static class ReferenceAndValue
- {
- public static void Demonstration()
- {
- stamp Stamp_1 = new stamp {Name="Premiere",Age=25 };
- stamp Stamp_2 = new stamp { Name = "Again", Age = 47 };
- int age = Stamp_1.Age;
- Stamp_1.Age = 22;
- stamp guru = Stamp_2;
- Stamp_2.Name = "Again Amend";
- Console.WriteLine("Stamp_1.Age=" + Stamp_1.Age);
- Console.WriteLine("age=" + age);
- Console.WriteLine("Stamp_2.Name=" + Stamp_2.Name);
- Console.WriteLine("guru.Name=" + guru.Name);
- }
- }
- }
复制代码 |