运行效果:
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace InnerList
{
class Program
{
static void Main(string[] args)
{
strList sl = new strList(); sl.Add("A");
sl.Add("B");
sl.Add("C"); Console.WriteLine(sl[]);
sl.Remove("A");
Console.WriteLine(sl[]); Console.ReadKey();
}
} /// <summary>
/// 用System.Collections.CollectionBase定义一个存储字符类型的列表类
/// </summary>
public class strList : System.Collections.CollectionBase
{
/// <summary>
/// 像列表中添加字符串
/// </summary>
/// <param name="str"></param>
public void Add(string str)
{
base.InnerList.Add(str);
} /// <summary>
/// 从列表中一处移除字符串
/// </summary>
/// <param name="str"></param>
public void Remove(string str)
{
base.InnerList.Remove(str);
} /// <summary>
/// 根据索引号,查找指定字符串
/// </summary>
/// <param name="Index"></param>
/// <returns></returns>
public string this[int Index]
{
get { return ((string)List[Index]); }
set { List[Index] = value; }
}
}
}