泛型类的一个简单示例

来源:互联网 发布:公安部 2017年欺诈数据 编辑:程序博客网 时间:2024/05/15 22:09
using System;using System.Collections;using System.Text;namespace Generics{    public class aList<T> : CollectionBase where T:new ()    {  public aList(){ }  public T this[int index]{   get { return (T)List[index]; }   set { List[index] = value; }  }  public int Add(T value){return List.Add(value);} }       class Program    {        static void Main(string[] args)        {            aList<Customer> customers = new aList<Customer>();            customers.Add(new Customer("Motown-Jobs"));            customers.Add(new Customer("Fatman's"));            foreach (Customer c in customers)                Console.WriteLine(c.CustomerName);            Console.ReadLine();        }    }    public class Customer     {        private string customerName = "";        public string CustomerName        {            get { return customerName; }            set { customerName = value; }        }        public Customer(string customerName)        {            this.customerName = customerName;        }        public Customer()        {        }    }}
原创粉丝点击