2021-09-14 17:04:34
2022-07-19 10:28:19
索引器是c#程序语言中类的一种成员,它使得对象可以像数组一样被索引,使程序看起来更直观,更容易编写。

C#通过提供索引器,可以象处理数组一样处理对象。特别是属性,每一个元素都以一个get或set方法暴露。
public class Skyscraper
{
Story[] stories;
public Story this [int index]
{
get
{
return stories [index];
}
set
{
if (value != null)
{
stories [index] = value;
}
}
}
//...
}
Skyscraper empireState = new Skyscraper (/*...*/);
empireState [102] = new Story ("The Top One", /*...*/);
【译注:索引器最大的好处是使代码看上去更自然,更符合实际的思考模式】
2021-06-07 04:53:05
2023-09-13 00:29:57
搜索引擎的工作原理是什么?为什么能找到我们想要的东西?
2024-02-20 06:27:54