如何将索引器与对象数组一起使用?
如果我们使用对象数组,我们如何使用索引器???
对于单个对象:
static void Main(string[] args)
{
MYInd mi = new MYInd();
mi[1] = 10;
Console.WriteLine(mi[1]);
mi[2, 10] = 100;
Console.WriteLine(mi[2]);
Console.WriteLine(mi[3, 10]);
对于对象数组应该做什么?
MYInd[] mir = new MYInd[3];
我们如何使用每个对象和索引器?
How can we use indexers if we are using array of objects???
For a single object:
static void Main(string[] args)
{
MYInd mi = new MYInd();
mi[1] = 10;
Console.WriteLine(mi[1]);
mi[2, 10] = 100;
Console.WriteLine(mi[2]);
Console.WriteLine(mi[3, 10]);
What should be done for array of objects?
MYInd[] mir = new MYInd[3];
How can we use each object and the indexer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有几个选项,如果你想迭代,你可以做
如果你想从数组中挑选一个特定的
MYInd
,你可以一步或两步完成
You have a couple of options, if you want to iterate you do
If you want to pick out a specific
MYInd
from the array you can do it in one stepor in two steps
但你可以将其想象为:
括号不是必需的,因为 [ 运算符是从左到右解析的(如 (1 + 2) + 3 == 1 + 2 + 3。我认为这称为左结合性,但我'我不确定 :-) )
请记住,您必须初始化数组和元素:
But you can imagine it as:
The brackets aren't necessary because the [ operator is parsed left to right (like (1 + 2) + 3 == 1 + 2 + 3. I think it's called left-associativity, but I'm not sure sure :-) )
Remember that you have to initialize BOTH the array and the elements: