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

Yangmingming 2003-07-24 02:05:00
我在学习时,感觉它就像是一个方面的代理工具,能过它,能调用一些方法,然后,得到一些希望的值,但却以产生大量类为代价?
不知,它有什么优势,在实际的程序设计中?
谢谢;
...全文
32 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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]);
}

}

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

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧