1.介绍
2.代码
{
internal class Program
{
public string FirstName;
public string LastName;
public string CityOfBirth;
public string this[int index]
{
set
{
switch (index)
{
case 0:
FirstName = value;
break;
case 1:
LastName = value;
break;
case 2:
CityOfBirth = value;
break;
}
}
get
{
switch (index)
{
case 0:
return FirstName;
case 1:
return LastName;
case 2:
return CityOfBirth;
default:
throw new ArgumentOutOfRangeException("index"); }
}
}
static void Main(string[] args)
{
Program program = new Program();
program[0] = "Park";
program[1] = "Jim";
Console.WriteLine(program[1] + " "+program[0]);
Console.ReadLine();
}
}
}