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 }

 

转载于:https://www.cnblogs.com/KTblog/p/4515647.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值