类与结构
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Ch09Ex03
7 {
8 /// <summary>
9 /// C#入门经典(第四版)第九章例子P185页
10 /// 结构类型
11 /// </summary>
12 class Program
13 {
14 static void Main(string[] args)
15 {
16 MyClass objectA = new MyClass();
17 MyClass objectB = new MyClass();
18 objectA.val = 10;
19 objectB.val = 20;
20 myStruct structA = new myStruct();
21 myStruct structB = new myStruct();
22 structA.val = 30;
23 structB.val = 40;
24 Console.WriteLine("objectA.val={0}", objectA.val);
25 Console.WriteLine("objectB.val={0}", objectB.val);
26 Console.WriteLine("structA.val={0}",structA.val);
27 Console.WriteLine("structB.val={0}",structB.val);
28 Console.ReadKey();
29 }
30
31 }
32 class MyClass
33 {
34 public int val;
35 }
36 struct myStruct
37 {
38 public int val;
39 }
40
41 }
42