C#索引器
来源:互联网 发布:java并发编程艺术 编辑:程序博客网 时间:2024/06/16 01:29
using System ;
/// <summary>
/// 索引器示例
/// </summary>
class StringCollection //建立一个字符串容器类
{
readonly int _count;
string[] str;
public StringCollection(int count)
{
if (count > 1)
{
_count = count;
str = new string[_count];
}
}
public string this[int index] //索引器
{
get
{
if (index >= 0 && index < _count)
return str[index];
else
return "error index!";
}
set
{
if (index < 0 || index >= _count)
throw new Exception("Out of Range!");
else
str[index] = value;
}
}
static void Main()
{
StringCollection test = new StringCollection(5);
test[0] = "Hello Word!";
test[2] = "Hi China!";
test[4] = "How do you do!";
for (int i = 0; i < 6; i++)
Console.WriteLine("String #{0} = {1}", i, test[i]);
StringCollection[] a = new StringCollection[3]; //定义一个3维StringCollection
for (int i =0;i<3;i++)
for (int j = 0; j < 2; j++)
{
a[i] = new StringCollection(2); //对每一个StringCollection调用构造函数
a[i][j] = i.ToString() + j.ToString();
Console.WriteLine(a[i][j]);
}
Console.Read();
}
}
- C#索引器
- C#索引器
- C#索引器
- C#中的索引器
- C#索引器
- C# 索引器
- C#索引器
- C#索引器
- C# 索引器
- C#索引器
- C#索引器
- C#索引器
- C#索引器
- c#属性 索引器
- C#的索引器
- C#索引器
- C#索引器
- C#索引器
- 卷积神经网络的网络结构——以LeNet-5为例
- 云星数据---Scala实战系列(精品版)】:Scala入门教程027-Scala实战源码-Scala 的特质 (接口)03
- 文档
- 设计模式-模版方法模式
- 中国互联网+礼品产业发展趋势分析
- C#索引器
- Linux环境下系统安装JDK
- 矩阵掩模操作
- Linux指令--whereis
- VMware Workstation 安装ubuntu
- 想要转人工智能,程序员该如何学习?
- 无人驾驶定位与贝叶斯滤波
- 近期的资源
- Java常用工具类集合(二)