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]);
                }
            }
        }
    }
  • 相关阅读:
    DIY 作品 及 维修 不定时更新
    置顶,博客中所有源码 github
    openwrt PandoraBox PBR-M1 极路由4 HC5962 更新固件
    使用 squid 共享 虚拟专用网至局域网
    第一次参加日语能力测试 N5
    libx264 libfdk_aac 编码 解码 详解
    开发RTSP 直播软件 H264 AAC 编码 live555 ffmpeg
    MFC Camera 摄像头预览 拍照
    http2 技术整理 nginx 搭建 http2 wireshark 抓包分析 server push 服务端推送
    plist 图集 php 批量提取 PS 一个个切
  • 原文地址:https://www.cnblogs.com/nele/p/4934709.html
Copyright © 2011-2022 走看看