首页 > 编程语言 > 详细

把C#对象变成数组技术---索引器(indexer)

时间:2017-01-16 00:58:31      阅读:147      评论:0      收藏:0      [点我收藏+]
 1 public class IndexerDemo
 2     {
 3         IList list = new List();
 4 
 5         public IndexerDemo()
 6         {
 7             list.Add("1");
 8             list.Add("2");
 9         }
10 
11         public string this[int i]
12         {
13             get
14             {
15                 return list[i];
16             }
17             set
18             {
19                 list[i] = value;
20             }
21         }
22 
23     }
24 
25 
26 //调用:
27             var id = new IndexerDemo();
28             var ids = id[1]; //这里,变数组了!

 

把C#对象变成数组技术---索引器(indexer)

原文:http://www.cnblogs.com/maoyan/p/6288284.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!