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#引入的一个新型的类成员,它使得类中的对象可以像数组那样方便.直观的被引用.索引器非常类似于属性,但索引器可以有参数列表,且只能作用在实例对象上,而不能在类上直接作用.定义 ...
随机推荐
- [KOJ6024]合并果子·改(强化版)
[COJ6024]合并果子·改(强化版) 试题描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多把这些果子堆排成一排,然后所有的果子合成一堆. 每一次合并 ...
- JavaScript深入浅出3-语句
慕课网教程视频地址:Javascript深入浅出 程序由语句组成,语句遵守特定语法规则 块 block {} 没有块级作用域 声明 var 异常 try catch finally 函 ...
- Kali Linux渗透基础知识整理(一):信息搜集
写在前面的废话:最近要给一些新人做培训,整理些东西,算不上什么太高端的内容,只是简单的整理下了,我觉得对于小白的话也还算是干货.在乌云水了几年,算不上什么大神水平,最近生活费紧张,现在打算在FreeB ...
- Github GUI 托管代码教程
附录:克隆仓库到本地:git clone https://github.com/chzeze/WeiboHomeCrawl.git
- 泛型约束 where T : class,new()
假如有这样一个方法签名 public List<T> GetSomethingList<T> (int a,int b,string c) where T:class,new( ...
- Iterator中hasNext(), next() 和ResultSet结果集的next方法的区别
接口 Iterator专门的迭代输出接口,将元素一个个进行判断,用hasNext() 判断是否有值,用next()方法把元素取出.hasNext() 如果仍有元素可以迭代,则返回 true.next( ...
- 【转】Nginx服务器的反向代理proxy_pass配置方法讲解
[转]Nginx服务器的反向代理proxy_pass配置方法讲解 转自:http://www.jb51.net/article/78746.htm 就普通的反向代理来讲Nginx的配置还是比较简单的, ...
- Unity3d 怪物死亡燃烧掉效果
效果 BurnToFadeOut.shader代码 Shader "BurnToFadeOut" { Properties { _StartColor ("Start C ...
- MySQL进程常见的State【转】
为了查阅方便,做个笔记. 通过show processlist查看MySQL的进程状态,在State列上面的状态有如下这些: Analyzing线程对MyISAM 表的统计信息做分析(例如, ANAL ...
- Win7下同时使用有线和无线时的优先级设置
终于找到这个问题的解决方案了!!!!我是通过方法1改跃点数实现的,方法2无效. http://linshengling.blog.163.com/blog/static/114651912012102 ...