我觉得这道题交待的不清楚,我不知道代码怎么写?不过也许是我的造诣太浅,看不懂题目,不清楚它到底考查的是什么。还请大家给些意见!先谢啦!

解决方案 »

  1.   


    public interface ISs
        {
            int this[int index]
            {
                set;
                get;
            }
        }
        class TempRecord: ISs
        {
            // Array of temperature values
            private float[] temps = new float[10] { 56.2F, 56.7F, 56.5F, 56.9F, 58.8F, 
                                                61.3F, 65.9F, 62.1F, 59.2F, 57.5F };        public float[] Temps
            {
                get { return temps; }
                set { temps = value; }
            }
                
            private int []ss = new int[10];
            // To enable client code to validate input 
            // when accessing your indexer.
            public int Length
            {
                get { return temps.Length; }
            }
            // Indexer of the class.
            // If index is out of range, the temps array will throw the exception.
            public float this[int index]
            {
                get
                {
                    return temps[index];
                }            set
                {
                    temps[index] = value;
                }
            }        //indexer of Interface ISs
            int ISs.this[int index]
            {
                set
                {
                    ss[index] = value;
                }
                get
                {
                    return ss[index];
                }
            }
        }    class Program
        {
            static void Main(string[] args)
            {
                TempRecord tr = new TempRecord();
                //ISs tr = new TempRecord();
                tr[0] = 2;
                tr.Temps[1] = 3;
                foreach(float f in tr)
                {
                    Console.WriteLine(tr[0]);
                }
            }
        }
      

  2.   

    用HashTable存储就好了using namespace Threading;
    ...
    HashTable table;
    for(int i=0;i<100;i++)
    {
        table.Add(i,"第i个数");
    }
    ...foreach(int i in table.Keys)
    {
        取第i个数=(int)table[i].Value;
    }
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            int[] intX = new int[100];
            
            public int this[int index]
            {
                get
                {
                    if (index < 0 || index > intX.Length)
                        throw new Exception("超出索引!");
                    return this.intX[index];
                }
                set
                {
                    if (index < 0 || index > intX.Length)
                        throw new Exception("超出索引!");
                    this.intX[index] = value;
                }
            }
        }
    }
      

  4.   

    class Program
        {
            int[] intX = new int[100];
            
            public int this[int index]
            {
                get
                {
                    if (index < 0 || index > intX.Length)
                        throw new Exception("超出索引!");
                    return this.intX[index];
                }
                set
                {
                    if (index < 0 || index > intX.Length)
                        throw new Exception("超出索引!");
                    this.intX[index] = value;
                }
            }
        }