C#的索引器
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#的索引器的更多相关文章
- 【.net 深呼吸】细说CodeDom(7):索引器
在开始正题之前,先补充一点前面的内容. 在方法中,如果要引用方法参数,前面的示例中,老周使用的是 CodeVariableReferenceExpression 类,它用于引用变量,也适用于引用方法参 ...
- C# 索引器,实现IEnumerable接口的GetEnumerator()方法
当自定义类需要实现索引时,可以在类中实现索引器. 用Table作为例子,Table由多个Row组成,Row由多个Cell组成, 我们需要实现自定义的table[0],row[0] 索引器定义格式为 [ ...
- C#基础回顾(三)—索引器、委托、反射
一.前言 ------人生路 ...
- C#索引器
索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 ...
- C#之索引器
实际中不使用这个东西,只做了解 using System; using System.Collections.Generic; using System.Linq; using System.Text ...
- C#属性-索引器-里氏替换-多态-虚方法-抽象-接口-泛型-
1.属性 //属性的2种写法 public class person { private string _name; public string Name { get { return _name; ...
- 《精通C#》索引器与重载操作符(11.1-11.2)
1.索引器方法结构大致为<modifier><return type> this [argument list],它可以在接口中定义: 在为接口声明索引器的时候,记住声明只是表 ...
- 描述一下C#中索引器的实现过程,是否只能根据数字进行索引?
不是.可以用任意类型. 索引器是一种特殊的类成员,它能够让对象以类似数组的方式来存取,使程序看起来更为直观,更容易编写. 1.索引器的定义 C#中的类成员可以是任意类型,包括数组和集合.当一个类包含了 ...
- C# 索引器使用总结
1.索引器(Indexer): 索引器允许类或者结构的实例按照与数组相同的方式进行索引.索引器类似于属性,不同之处在于他们的访问采用参数. 最简单的索引器的使用 /// <summary> ...
- C# 类中索引器的使用二
索引器(Indexer)是C#引入的一个新型的类成员,它使得类中的对象可以像数组那样方便.直观的被引用.索引器非常类似于属性,但索引器可以有参数列表,且只能作用在实例对象上,而不能在类上直接作用.定义 ...
随机推荐
- [codevs3729]飞扬的小鸟
[codevs3729]飞扬的小鸟 试题描述 输入 输出 输出文件名为 bird.out. 共两行. 第一行,包含一个整数,如果可以成功完成游戏,则输出 1,否则输出 0. 第二行,包含一个整数,如果 ...
- word20161205
cluster-aware application / 支持群集的应用程序 cluster-unaware application / 不支持群集的应用程序 Cluster.exe CNAME (ca ...
- 标签语义化之常用HTML标签
一.布局的理解误区 网络上流行管新型的布局方式叫“DIV+CSS”,其实是一个错误的理解,导致了很多人过度依赖与滥用DIV标签, HTML提供了我们一共七八十个标签,其中常用的有三十个左右,DIV不过 ...
- Ucenter,Discuz
http://www.zb7.com/discuz/ (详细资料网站) Discuz主要是配置前台的模板制作,在二次开发时. UCenter主要是客户端的数据库的链接.client/.
- Android的一种MVP模式框架
今天给大家分享的是一种将view的初始化和逻辑与activity分离的架构,采用的是mvp模式.但令人遗憾的是,这仅仅是一个新的思路,我在实际使用中发现其并不能完全将UI逻辑与activity分开,所 ...
- php中set_time_limit()函数运用
当你的页面有大量数据时,建议使用set_time_limit()来控制运行时间,默认是30s,所以需要你将执行时间加长点. 如 set_time_limit(800) ,其中将秒数设为0 ,表示持续 ...
- 【架构】RPC 使用 Haproxy、keepalive作为负载均衡
参考资料: Haproxy+keepalived 高可用负载: http://www.tuicool.com/articles/qY7Rz23 keepalived原理(主从配置+haproxy)及 ...
- 针对跑MySQL的Linux优化【转】
本文来自:http://www.mysqlsupport.cn/linux-performance-tuning-tips-mysql/ 因为很多MySQL的生产环境都在Linux下,我决定指出一些L ...
- springMVC中ajax的使用
springMVC中使用ajax有两种方法,第一种是根据servletAPI来使用ajax,第二种是根据springMVC给我们提供的API来使用. 一.根据servletAPI: springMVC ...
- AUTOSSH,ssh反向代理
在本地机器 1)ssh-keygen 2)ls ~/.ssh/ 应该有三个文件 id_rsa id_rsa.pub known_hosts 拷贝id_rsa.pub到远程服务器,然后在 ...