public class Point { private double x, y; public Point(double X, double Y) { x = X; y = Y; } public override string ToString() { return String.Format("X: {0} , Y: {1}", x, y); } } public class Points { Point[] points; public Points(Point[] Points) { points = Points; } public int PointNumber { get { return points.Length; } } public Point this[int Index] { get { return points[Index]; } } } class IndexClass { public string this[int index] { get { switch (index) { case 1: return "一"; case 2: return "二"; case 3: return "三"; case 4: return "四"; default: return "unkonw number"; } } } public string this[string str] { get { return str; } } public object this[object o] { get { return new object();//这个地方有点意思 } } } class Program { static void Main(string[] args) { IndexClass ic = new IndexClass(); Console.WriteLine(ic["字符串索引"]); Console.WriteLine(ic[4]); Console.WriteLine(ic[new object()].GetType()); Point[] tmpPoints = new Point[10]; for (int i = 0; i < tmpPoints.Length; i++) { tmpPoints[i] = new Point(i, Math.Sin(i)); } Points tmpObj = new Points(tmpPoints); for (int i = 0; i < tmpObj.PointNumber; i++) { Console.WriteLine(tmpObj[i]); } Console.ReadKey(); } }