日期:2014-05-17  浏览次数:20872 次

c# 索引器的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test11
{
    class Ball
    {
        string[] winners;                              //定义奖励等级
        int [] prize;                                  //定义奖励金额
        int winner;                                    
        public Ball(int length)                         //定义构造函数                      
        {
            winners = new string[length];               //设置数组长度
            prize = new int [length];                   //设置数组长度
        }
        public string Winner                            //定义属性
        {
            set
            {
                winners[winner] = value;                //通过属性为winners数组元素赋值
            }
        }
        public int this[int index]                      //定义索引器
        {
            get
            {
                return prize[index];                    //通过索引器取值
            }
            set
            {
                prize[index] =&nb