zoukankan      html  css  js  c++  java
  • c# 重写索引

    //using System;
    //using System.Collections.Generic;
    //using System.Text;
    //namespace 索引
    //{
    //    class Program
    //    {
    //        static void Main(string[] args)
    //        {
    //        }
    //    }
    //}
    //using System;
    //class MyIndexer
    //{ private string [ ]  myArray=new string[4];
    //  public string this[int index]
    //   { get
    //        {  if(index<0||index>=4)
    //            return null;
    //           else 
    //           return myArray[index];
    //        }
    //    set
    //      {   if(!(index<0||index>=4))
    //           myArray[index]=value;
    //      }    
    //    }
    //}
    //class MainClass
    //{    
    //        static void Main()
    //        {  MyIndexer idx=new MyIndexer();
    //            idx[0]="vivid";
    //            idx[1]="Miles";
    //           for(int i=0;i<=3;i++)
    //            Console.WriteLine("Element #{0}={1}",i,idx[i]);
    //        }
    //}
    //////////////////////////////////////////////
    //class SampleCollection<T>
    //{
    //    private T[] arr = new T[100];
    //    public T this[int i]
    //    {
    //        get
    //        {
    //            return arr[i];
    //        }
    //        set
    //        {
    //            arr[i] = value;
    //        }
    //    }
    //}
    //// This class shows how client code uses the indexer
    //class Program
    //{
    //    static void Main(string[] args)
    //    {
    //        SampleCollection<string> stringCollection = new SampleCollection<string>();
    //        stringCollection[0] = "Hello, World";
    //        System.Console.WriteLine(stringCollection[0]);
    //    }
    //}
    ///////////////////////
    namespace A
    {
        class test
        {
            private int[] arry = new int[5];
            //protected int Arry
            //{
            //    get
            //    {
            //        for (int i = 0; i < 5; i++)
            //        {
            //            return arry[i];
            //        }
            //    }
            //    set
            //    {
            //        for (int i = 0; i < 5; i++)
            //        {
            //            arry[i] = value;
            //        }
            //    }
            //}
            public int this[int index]
            {
                get
                {
                    return arry[index];
                }
                set
                {
                    arry[index] = value;
                }
            }
        }
        class print
        {
            static void Main()
            {
                test arr = new test();
                for (int i = 0; i < 5; i++)
                {
                    arr[i] = i * i;
                }
                for (int i = 0; i < 5; i++)
                {
                    System.Console.WriteLine("arr[{0}]={1}", i + 1, arr[i]);
                }
            }
        }
    }
  • 相关阅读:
    修改系统策略 作为服务登录
    PlayStation Suite(PSS)快速预览
    Python异常处理
    误操作把/bin目录移动到其他目录下的恢复方法
    SQL Prompt 自动过期反复激活防失效注册后隔一段时间莫名无法使用的处理
    [转帖]SQL SERVER 2005 同步复制技术
    动网论坛修改笔记
    网线的做法
    风讯修改记录
    远程桌面中调出任务管理器
  • 原文地址:https://www.cnblogs.com/nele/p/4934709.html
Copyright © 2011-2022 走看看