using System;
public class MyCollection
{
private int[] data = new int[10];
public int this[int index, bool square]
{
get
{
if (square)
return data[index] * data[index];
else
return data[index];
}
set
{
if (square)
data[index] = (int)Math.Sqrt(value);
else
data[index] = value;
}
}
public int this[string name]
{
get
{
switch (name.ToLower())
{
case "first":
return data[0];
case "last":
return data[data.Length - 1];
default:
throw new ArgumentException("Invalid index parameter.");
}
}
}
public int this[int index]
{
get { return data[index]; }
}
}
public class Program
{
public static void Main()
{
MyCollection collection = new MyCollection();
collection[0, false] = 5;
collection[1, false] = 10;
collection[2, false] = 15;
collection[3, false] = 20;
Console.WriteLine(collection[0, false]);
Console.WriteLine(collection[1, true]);
Console.WriteLine(collection["first"]);
Console.WriteLine(collection["last"]);
Console.WriteLine(collection[2]);
Console.ReadLine();
}
}