1、数据类型的进化

 C#1中实现Product类型代码

 1 public class Product
 2     {
 3         string name;
 4         public string Name
 5         {
 6             get { return name; }
 7         }
 8 
 9         decimal price;
10         public decimal Price
11         {
12             get { return price; }
13         }
14 
15         public Product(string name, decimal price)
16         {
17             this.name = name;
18             this.price = price;
19         }
20      
21         public static ArrayList GetSampleProducts()
22         {
23             ArrayList list = new ArrayList();
24             list.Add(new Product("West Side Story", 9.99m));
25             list.Add(new Product("Assassins", 14.99m));
26             list.Add(new Product("Frogs", 13.99m));
27             list.Add(new Product("Sweeney Todd", 10.99m));
28             return list;
29            
30         }
31 
32         public override string ToString()
33         {
34             return string.Format("{0}: {1}", name, price);
35           
36         }
37       
38 
39     }
View Code

相关文章: