自定义泛型集合,分别实现增删改查和排序操作?

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


 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]);
            }
        }

    }


    class Custom<T> : IEnumerable where T : IComparable
    {
        List<T> list;
        public Custom()//初始化集合
        {
            list = new List<T>();
        }        
        public int Capacity//封装属性
        {
            get { return list.Count; }
        }
        public void Add(T value)//添加元
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值