using System;
using System.Collections;
using System.Collections.Generic;
using System.IO; namespace codeTest
{ class Program
{ static void Main(string[] args)
{
IndexTest indexname = new IndexTest();
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
indexname[] = "";
for (int i = ; i < ; i++)
{
Console.WriteLine(indexname[i]);
} Console.WriteLine(indexname[""]);
Console.WriteLine(indexname[""]);
Console.WriteLine(indexname[""]);
IndexTest1 indextest1 = new IndexTest1();
Console.WriteLine(indextest1[]);
Console.WriteLine(indextest1[]);
Console.WriteLine(indextest1[]);
Console.ReadLine();
} public class IndexTest
{
string[] indexName;
public IndexTest()
{
indexName = new string[] { "", "", "", "", "", "", "", "", "", "" };
} public string this[int index]
{
get
{
string tmp;
if (index >= && index <= )
{
tmp = indexName[index];
}
else
{
tmp = "";
}
return tmp;
}
set
{
if (index >= && index <= )
{
indexName[index] = value;
}
}
} public int this[string name]
{
get
{
int index = ;
while (index < indexName.Length)
{
if (indexName[index] == name)
{
return index;
}
index++;
} return -;
}
} } public interface IIndexTest
{
int this[int index]
{
get;
set;
}
} public class IndexTest1 : IIndexTest
{
int[] array = new int[] { , , , , }; public int this[int index]
{
get
{
return array[index];
}
set
{
array[index] = value;
}
}
} } }

C#的索引器的更多相关文章

  1. 【.net 深呼吸】细说CodeDom(7):索引器

    在开始正题之前,先补充一点前面的内容. 在方法中,如果要引用方法参数,前面的示例中,老周使用的是 CodeVariableReferenceExpression 类,它用于引用变量,也适用于引用方法参 ...

  2. C# 索引器,实现IEnumerable接口的GetEnumerator()方法

    当自定义类需要实现索引时,可以在类中实现索引器. 用Table作为例子,Table由多个Row组成,Row由多个Cell组成, 我们需要实现自定义的table[0],row[0] 索引器定义格式为 [ ...

  3. C#基础回顾(三)—索引器、委托、反射

    一.前言                                                                                       ------人生路 ...

  4. C#索引器

    索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 ...

  5. C#之索引器

    实际中不使用这个东西,只做了解 using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  6. C#属性-索引器-里氏替换-多态-虚方法-抽象-接口-泛型-

    1.属性 //属性的2种写法 public class person { private string _name; public string Name { get { return _name; ...

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

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

  8. 描述一下C#中索引器的实现过程,是否只能根据数字进行索引?

    不是.可以用任意类型. 索引器是一种特殊的类成员,它能够让对象以类似数组的方式来存取,使程序看起来更为直观,更容易编写. 1.索引器的定义 C#中的类成员可以是任意类型,包括数组和集合.当一个类包含了 ...

  9. C# 索引器使用总结

    1.索引器(Indexer): 索引器允许类或者结构的实例按照与数组相同的方式进行索引.索引器类似于属性,不同之处在于他们的访问采用参数. 最简单的索引器的使用 /// <summary> ...

  10. C# 类中索引器的使用二

    索引器(Indexer)是C#引入的一个新型的类成员,它使得类中的对象可以像数组那样方便.直观的被引用.索引器非常类似于属性,但索引器可以有参数列表,且只能作用在实例对象上,而不能在类上直接作用.定义 ...

随机推荐

  1. eclipse添加velocity项目

    1.首先添加jar包,记得包含以下的主要两个类别 2.新建一个servlet类(继承自VelocityViewServlet) package com.servlet; import java.uti ...

  2. 这些情况下onReume不应该是你的选择

    面试Android程序员的时候问过以下几个基本问题,得到的回答经常不尽人意: 1, Activity A跳转到Activity B,Activity B完成后,Activity A要刷新一下自己的数据 ...

  3. Tomcat配置文件server.xml详解

    <?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOW ...

  4. IntelliJ IDEA License

    http://jetbrains.tech/ http://jetbrains.tencent.click/

  5. Sublime text2 插件推荐

    HTML-CSS-JS Prettify:  前端插件,使用 ctrl+shift+h 格式化代码

  6. 《oracle每日一练》oracle截取字符的函数

    转载 在Oracle中 可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符. 在一个字符串中查找指定的字符,返回被查找到的指定的字符的位置. 语法: instr(sourceStri ...

  7. jq获取元素

    <tr><td><div id="add"></div></td></tr>$("#add&quo ...

  8. vim python设置

    http://www.cnblogs.com/Leo-Forest/archive/2012/04/06/2435237.html http://linux-wiki.cn/wiki/zh-hans/ ...

  9. Effective C++ -----条款16:成对使用new和delete时要采取相同形式

    如果你在new表达式中使用[],必须在相应的delete表达式中也使用[].如果你在new表达式中不使用[],一定不要在相应的delete表达式中使用[].

  10. malloc原理和内存碎片

    当一个进程发生缺页中断的时候,进程会陷入内核态,执行以下操作: 1.检查要访问的虚拟地址是否合法 2.查找/分配一个物理页 3.填充物理页内容(读取磁盘,或者直接置0,或者啥也不干) 4.建立映射关系 ...