C#索引器1 数字作为索引号
2016-03-08 11:28
246 查看
5.索引器 数字作为索引号
public class IndexerClass
{
private string[] name = new string[2];
public string this[int index]
{
get
{
if (index < 2)
{
return name[index];
}
return null;
}
set
{
if (index < 2)
{
name[index] = value;
}
}
}
}
public class Test
{
public static void Main(string[] args)
{
IndexerClass ic = new IndexerClass();
ic[0] = "sssssss";
ic[1] = "bbbbbbb";
Console.WriteLine("ic[{0}] 为 {1}",0,ic[0]);
Console.WriteLine("ic[{0}] 为 {1}",1,ic[1]);
Console.ReadKey();
}
}
public class IndexerClass
{
private string[] name = new string[2];
public string this[int index]
{
get
{
if (index < 2)
{
return name[index];
}
return null;
}
set
{
if (index < 2)
{
name[index] = value;
}
}
}
}
public class Test
{
public static void Main(string[] args)
{
IndexerClass ic = new IndexerClass();
ic[0] = "sssssss";
ic[1] = "bbbbbbb";
Console.WriteLine("ic[{0}] 为 {1}",0,ic[0]);
Console.WriteLine("ic[{0}] 为 {1}",1,ic[1]);
Console.ReadKey();
}
}
相关文章推荐
- C# Socket
- C#操作图片存入XML和显示XML图片
- C#实现性能计数器
- C# 调用API 操作串口
- C#中双问号、双冒号等几个特殊关键字
- C#(同步调用、异步调用、异步回调)
- C# -- 使用委托
- C#实现DataTable转换成IList的方法
- C#.Net前台线程与后台线程的区别
- C#正则表达式
- C#实现从多列的DataTable里取需要的几列
- 认识C#的轮廓
- C# -- 异常和异常处理
- C#利用Zxing.net生成二维码和条形码并实现打印的功能
- C# 委托及各种写法
- 用C#读取相片(JPG图片)的EXIF信息的方法
- C# 汉字转拼音(支持GB2312字符集中所有汉字)
- internal(C# 参考)
- 【C#进阶系列】06 类型和成员基础
- 【C#进阶系列】06 类型和成员基础