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]);
                }
            }
        }
    }
  • 相关阅读:
    滚轮事件的防冒泡、阻止默认行为的代码(效果是:只让当前div滚动,连当前文档都不滚动的效果)
    js原生封装getClassName()方法-ie不支持getElementsByClassName,所以要自己实现获取类名为className的所有元素
    使用 RequireJS 优化 Web 应用前端
    javascript的页面加载及性能优化(兼容IE7)
    JavaScript中的this陷阱的最全收集--没有之一
    mysql 配置MHA
    mysql 在linux下的完整安装过程
    vue 开发系列(八) 动态表单开发
    vue 开发系列(七) 路由配置
    vue 开发系列(六) 企业微信整合
  • 原文地址:https://www.cnblogs.com/nele/p/4934709.html
Copyright © 2011-2022 走看看