C# - InnerList

运行效果:

 

 

 

代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace InnerList
 7 {
 8     class Program
 9     {
10         static void Main(string[] args)
11         {
12             strList sl = new strList();
13 
14             sl.Add("A");
15             sl.Add("B");
16             sl.Add("C");
17 
18             Console.WriteLine(sl[1]);
19             sl.Remove("A");
20             Console.WriteLine(sl[1]);
21 
22             Console.ReadKey();
23         }
24     }
25 
26     /// <summary>
27     /// 用System.Collections.CollectionBase定义一个存储字符类型的列表类
28     /// </summary>
29     public class strList : System.Collections.CollectionBase
30     {
31         /// <summary>
32         /// 像列表中添加字符串
33         /// </summary>
34         /// <param name="str"></param>
35         public void Add(string str)
36         {
37             base.InnerList.Add(str);
38         }
39 
40         /// <summary>
41         /// 从列表中一处移除字符串
42         /// </summary>
43         /// <param name="str"></param>
44         public void Remove(string str)
45         {
46             base.InnerList.Remove(str);
47         }
48 
49         /// <summary>
50         /// 根据索引号,查找指定字符串
51         /// </summary>
52         /// <param name="Index"></param>
53         /// <returns></returns>
54         public string this[int Index]
55         {
56             get { return ((string)List[Index]); }
57             set { List[Index] = value; }
58         }
59     }
60 }

 

posted on 2015-05-19 21:48  ultrastrong  阅读(617)  评论(0编辑  收藏  举报