原创  C#中类的索引器 收藏

 通常来说,C#中类的索引器通常只有一个,就是THIS,但也可以有无数个,只要你的参数列表不同就可以了
索引器和返回值无关

  1.   class A
  2.     {
  3.        
  4.         public List<string> items = new List<string>();
  5.         public string this[int i]
  6.         {
  7.             get { return items[i]; }
  8.             set { items.Insert(i, value); }
  9.         }
  10.         
  11.         public int this[string i]
  12.         {
  13.             get { return int.Parse(items[int.Parse(i)]); }
  14.             set { items.Insert(int.Parse(i), value.ToString()); }
  15.         }

发表于 @ 2008年11月02日 07:47:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:一个多播委托 | 新一篇:“记住我的密码” 消失了?

  • 发表评论
  • 评论内容:
  •  
Copyright © andyhooo
Powered by CSDN Blog