using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3._3{ class sampleIndex { private double[] arr = new double[5] { 1, 2, 3, 4, 5 }; public double this[int index] { get { if (index < 0 || index >= 5) { return 0; } else { return arr[index]; } } set { if (index >= 0 && index <= 5) { arr[index] = value; } } } } class Program { static void Main(string[] args) { sampleIndex smpIndex = new sampleIndex(); smpIndex[3] = 3.5; for (int i = 0; i < 6; i ) { Console.WriteLine("smpIndex[{0}]={1}", i, smpIndex[i]); } Console.ReadLine(); } }}
评论