c#_索引器(Indexer)
来源:互联网 发布:windows phone7.8评测 编辑:程序博客网 时间:2024/05/15 02:21
//索引器(Indexer) 允许一个对象可以像数组一样被索引。当您为类定义一个索引器时,该类的行为就会像一个 虚拟数组(virtual array) 一样。您可以使用数组访问运算符([ ])来访问该类的实例。//语法 如下: //element-type this[int index] //{// // get 访问器// get // {// // 返回 index 指定的值// } // // set 访问器// set // {// // 设置 index 指定的值 // }//}public class Indexer //: IEnumerable{static public int size = 10;private string[] indexerList = new string[size];//构造函数赋初值public Indexer(){for (int i = 0; i < indexerList.Length; i++)indexerList[i] = "DefaultValue";}//c# 索引器public string this[int index]{get{if (index < 0 || index > size)return "";return indexerList[index] == null ? string.Empty : indexerList[index].ToString();}set{if (index < 0 || index > size)throw new Exception("超出索引范围: 0~9");indexerList[index] = value;}}//实现foreach枚举public IEnumerator GetEnumerator(){return this.indexerList.GetEnumerator();} }//索引器调用测试Indexer id = new Indexer();id[0] = "0";id[1] = "1";id[6] = "6";foreach (string strTmp in id)Console.WriteLine(strTmp);Console.ReadKey();//0//1//////////6//////
0 0
- c#_索引器(Indexer)
- 【C#】索引器(Indexer)
- C# 索引器(Indexer)
- C# 索引器(Indexer)
- C# 索引器(Indexer)
- C#索引器(Indexer)
- 索引器-Indexer(MSDN)
- INDEXER索引器例子
- 索引器indexer学习
- 索引器indexer
- 索引器indexer
- 索引器(Indexer)
- C#.NET常见问题(FAQ)-索引器indexer有什么用
- C#梳理【索引器Indexer】
- the Indexer(索引器) in C#
- C# 类索引器Class Indexer
- C# Indexer 索引
- 索引器:Both Indexer and Switch have two types
- java输出系统时间
- spring MVC 框架的搭建(myeclipse +maven)--(下)
- uitableview去掉最后一行cell的底线
- RobotArt-气缸去毛刺案例
- 初学ML笔记N0.4——梯度下降的优化
- c#_索引器(Indexer)
- Android App 分享功能实现
- localhost: Error: JAVA_HOME is not set.
- mysql root密码重置报错
- fiddler4 设置断点,修改request信息
- hibernate jpa 注解 @Temporal(TemporalType.DATE) 格式化时间日期,页面直接得到格式化类型的值
- 双击禁止选中文本
- Ajax学习
- Django表单处理