当前位置:编程学习 > C#/ASP.NET >>

自定义Collection类

[csharp] view plaincopyprint?
using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
 
namespace MyCollection 

    class Program 
    { 
        static void Main(string[] args) 
        { 
            Collection names = new Collection(); 
 
            names.Add("David"); 
            names.Add("Bernica"); 
            names.Add("Raymond"); 
 
            foreach (Object name in names) 
            { 
                Console.WriteLine(name); 
            } 
        } 
    } 
 
    /// <summary>  
    /// 构造自己和集合类  
    /// </summary>  
    public class Collection:CollectionBase 
    { 
        // 增加  
        public void Add(Object item) 
        { 
            this.InnerList.Add(item); 
        } 
 
        // 删除  
        public void Remove(Object item) 
        {    
            this.InnerList.Remove(item); 
        } 
 
        // 总数,用new 关键字隐藏父类实现  
        public new int Count() 
        { 
            return InnerList.Count; 
        } 
 
        // 清空  
        public new void Clear() 
        { 
            this.InnerList.Clear(); 
        } 
    } 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCollection
{
    class Program
    {
        static void Main(string[] args)
        {
            Collection names = new Collection();

            names.Add("David");
            names.Add("Bernica");
            names.Add("Raymond");

            foreach (Object name in names)
            {
                Console.WriteLine(name);
            }
        }
    }

    /// <summary>
    /// 构造自己和集合类
    /// </summary>
    public class Collection:CollectionBase
    {
        // 增加
        public void Add(Object item)
        {
            this.InnerList.Add(item);
        }

        // 删除
        public void Remove(Object item)
        {  
            this.InnerList.Remove(item);
        }

        // 总数,用new 关键字隐藏父类实现
        public new int Count()
        {
            return InnerList.Count;
        }

        // 清空
        public new void Clear()
        {
            this.InnerList.Clear();
        }
    }
}


 

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,