//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]);
            }
        }
    }
}

c# 重写索引的更多相关文章

  1. 《精通C#》索引器与重载操作符(11.1-11.2)

    1.索引器方法结构大致为<modifier><return type> this [argument list],它可以在接口中定义: 在为接口声明索引器的时候,记住声明只是表 ...

  2. 关于索引删除的策略IndexDeletionPolicy

    关于索引删除的策略IndexDeletionPolicy . public IndexWriter(Directory d, Analyzer a, boolean create)          ...

  3. Oracle优化的几个简单步骤

    数据库优化的讨论可以说是一个永恒的主题.资深的Oracle优化人员通常会要求提出性能问题的人对数据库做一个statspack,贴出数据库配置等等.还有的人认为要抓出执行最慢的语句来进行优化.但实际情况 ...

  4. MapReduce: 一种简化的大规模集群数据处理法

    (只有文字没有图,图请参考http://research.google.com/archive/mapreduce.html) MapReduce: 一种简化的大规模集群数据处理法 翻译:风里来雨里去 ...

  5. C# 语言规范_版本5.0 (第10章 类)

    1. 类 类是一种数据结构,它可以包含数据成员(常量和字段).函数成员(方法.属性.事件.索引器.运算符.实例构造函数.静态构造函数和析构函数)以及嵌套类型.类类型支持继承,继承是一种机制,它使派生类 ...

  6. MySql 性能调优策略

    本主题调优针对于my.cnf配置来做详细的参数说明 示例配置如下: #cat my.cnf # MySQL client library initialization. [client] port = ...

  7. C#6.0语言规范(十) 类

    类是可以包含数据成员(常量和字段),函数成员(方法,属性,事件,索引器,运算符,实例构造函数,析构函数和静态构造函数)和嵌套类型的数据结构.类类型支持继承,这是一种派生类可以扩展和专门化基类的机制. ...

  8. Oracle表的优化一点见解

    Oracle优化的几个简单步骤 数据库优化的讨论可以说是一个永恒的主题.资深的Oracle优化人员通常会要求提出性能问题的人对数据库做一个statspack,贴出数据库配置等等.还有的人认为要抓出执行 ...

  9. Pro ASP.Net Core MVC 6th 第四章

    第四章 C# 关键特征 在本章中,我描述了Web应用程序开发中使用的C#特征,这些特征尚未被广泛理解或经常引起混淆. 这不是关于C#的书,但是,我仅为每个特征提供一个简单的例子,以便您可以按照本书其余 ...

随机推荐

  1. Android自定义单选,自定义选中状态

    如图,此布局用GrildView实现,弹出框由Activity的dialog样式实现. 屏蔽系统GrildView点击背景黄色: grildview.setSelector(new ColorDraw ...

  2. 更简单地进行Auto Layout--SnapKit 支持swift

    OC下的autolayout神器Masonry大家已经很熟悉了.但是masonry在swift下使用并不方便.所以同一个团队开发出了swift下的autolayout库:SnapKitsnapkit从 ...

  3. ArrayList List<T> T[] Array

    ArrayList    其实就是一个存储obj列表的类 ArrayList 接受 null 作为有效值并且允许重复的元素. 不保证会对 ArrayList 排序. 在执行需要对 ArrayList ...

  4. SQL Serve允许远程连接的解决方法

    (一)用户需要做的第一件事是检查SQL数据库服务器中是否允许远程链接.在SQL 2008服务器中可以通过打开SQL Server 2008管理项目(SQL Server 2008 Management ...

  5. windows API 开发飞机订票系统 图形化界面 (四)

    接下来的是录入航班.修改航班信息功能的实现: //录入航班 BOOL EntryFlight(HWND hEntryDlg){ TCHAR szDiscount[]; TCHAR szFare[],s ...

  6. Scala 中的函数式编程基础(一)

    主要来自 Scala 语言发明人 Martin Odersky 教授的 Coursera 课程 <Functional Programming Principles in Scala>. ...

  7. tomcat服务器上webapps里的文件名和项目名称不一样,修改方法

    第一种方法:打开工程所在目录,找到一个 .mymetadata的文件,用记事本等打开,内容大致如下: <?xml version="1.0" encoding="U ...

  8. Java基础-关键字-final

    在Java中,final关键字可以用来修饰类.方法和变量(包括成员变量和局部变量).下面就从这三个方面来了解一下final关键字的基本用法. 1.修饰类 当用final修饰一个类时,表明这个类不能被继 ...

  9. jdownload的使用

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  10. 【Gym 100971A】Treasure Island

    题意 题目链接给你一个地图,'#'代表水,'.'代表陆地,'?'代表擦去的地图,可能是'#'也可能是'.'.地图中本该只有一块相连的陆地,若只有一种方案则输出确定的地图.若有多种方案,则输出‘Ambi ...