请,哪位学友,说一说,c#中,类的索引,是如何理解的,有什么作用?

Yangmingming 2003-07-24 02:05:00
我在学习时,感觉它就像是一个方面的代理工具,能过它,能调用一些方法,然后,得到一些希望的值,但却以产生大量类为代价?
不知,它有什么优势,在实际的程序设计中?
谢谢;
...全文
22 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_bob 2003-07-24
  • 打赏
  • 举报
回复
和属性差不多,都是属于函数一列.
并不会产生大量类呀?!


using System;
public class TestClass
{
private string[] s;

public TestClass(uint length)
{
s=new string[length];
}

public string this[uint index]
{
get
{
return(s[index]);
}
set
{
s[index]=value;
}
}

public static void Main()
{
TestClass s=new TestClass(10);
for(uint i=0;i<10;i++)
s[i]=i.ToString();

uint index=5;
Console.WriteLine(s[index]);
}

}

在实际中,如果有一组相同数据并希望用户访问,可以采用.很方便
相关推荐
发帖
C#

10.9w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-24 02:05
社区公告

让您成为最强悍的C#开发者