
class Program
{static void Main(string[] args)
{
Custom<string> custom = new Custom<string>();
custom.Add("456");
custom.Add("123");
custom.Add("789");
custom.SystemSort();
custom.QuickSort(0, 2);
custom.InsertSort();
custom.ChooseSort();
custom.BubbleSort();
foreach (string str in custom)
{
Console.WriteLine(str);
}
for (int i = 0; i < custom.Capacity; i++)
{
Console.WriteLine(custom[i]);
}
}
}

{
List<T> list;
public Custom()//初始化集合
{
list = new List<T>();
}
public int Capacity//封装属性
{
get { return list.Count; }
}
public void Add(T value)//添加元素
{
list.Add(value);
}
public void Remove(T value)//删除指定元素
{

本文介绍了如何自定义泛型集合,详细阐述了利用泛型特性实现增删改查基本操作,并探讨了如何为集合添加排序功能。通过示例代码,展示了如何使用索引器增强集合的访问体验。

2146

被折叠的 条评论
为什么被折叠?



