110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestIndex
{
public class SpellString
{
protected string[] theString=new string[10];
public SpellString()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(theString[i]);
}
}
public string this[int index]
{
get
{
if (index < 0 || index >= 10)
{
//错误处理
}
else
return theString[index];
}
set
{
if (index < 0 || index >= 10)
{
//错误处理
}
else
theString[index] = value;
}
}
}
public class Program
{
static void Main(string[] args)
{
SpellString thisString = new SpellString();
thisString[2] = "HEllo";
thisString[3] = "world";
for (int i=0;i<10;i++)
{
Console.WriteLine("value:{0}={1}",i,thisString[i]);
}
}
}
}