本文介绍了索引器的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不了解索引器的目的.示例:

Not understand the purpose of Indexers. Example:

class MyCls
{
   object[] myArr = new object[];
   public object this[int i]
   {
      get{return myArr[i];}
      set{myArr[i] = value;}
   }
}


为什么不只为myArr创建一个属性并通过它的属性访问它呢?


Why not just create a property for myArr and access it through it''s property?
What''s the advantage and/or purpose of using an Indexer?

推荐答案

这仅是语法糖,请参见 http://en.wikipedia.org/wiki/Syntactic_sugar [ ^ ].

This is nothing more than the syntactic sugar, see http://en.wikipedia.org/wiki/Syntactic_sugar[^].

作为语法糖,这是非常好的糖,它遵循其他语言的传统.

Being the syntactic sugar, this is very nice sugar, following nice tradition from other languages.



这篇关于索引器的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 19:10