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]);
                }
            }
        }
    }
  • 相关阅读:
    050医疗项目-模块五:权限设置-第三方系统的接入
    049医疗项目-模块五:权限设置
    047医疗项目-模块四:采购单模块—采购单审核提交(Dao,Service,Action三层)
    046医疗项目-模块四:采购单模块—采购单审核(Dao,Service,Action三层)
    Netty原理分析
    Java集群优化——使用Dubbo对单一应用服务化改造
    知乎问答:现在程序员的工资是不是被高估了?
    一文理解 Java NIO 核心组件
    深入理解 Spring 事务原理
    完美主义对程序员的影响
  • 原文地址:https://www.cnblogs.com/nele/p/4934709.html
Copyright © 2011-2022 走看看