list [i]是C#中list.get_item(i)的别名吗? [英] Is list[i] an alias for list.get_item(i) in C#?
问题描述
我正在传递一个lambda表达式作为参数.
I'm passing a lambda expression as a parameter.
在这种情况下,someObject
具有一个名为property
的属性,可通过someObject.property
访问.
In this case, someObject
has a property called property
accessible with someObject.property
.
我通过时:o => o.childListOfObjects[0].property
其中childListOfObjects
是List<someObejct>
和,
expression.Body
返回o => o.childListOfObjects.get_Item(0).property
.
跳到最后:
list[i]
是C#中list.get_item(i)
的别名吗?
推荐答案
是的,属性通常只是get_PropertyName
和set_PropertyName
方法周围的语法糖.
Yes, properties in general are just syntactic sugar around get_PropertyName
and set_PropertyName
methods.
索引器-例如,list[i]
只是一种特殊类型的属性,基本上是get_Item(i)
和set_Item(i)
方法周围的语法糖.
Indexers -- for example, list[i]
-- are just a special type of property, basically syntactic sugar around get_Item(i)
and set_Item(i)
methods.
(请注意,不一定必须将索引器属性称为Item
, IndexerNameAttribute
.)
(Note that the indexer property doesn't necessarily have to be called Item
, but that's what it's called on List<T>
, and that's the default name given to indexers on custom types too unless you override it using IndexerNameAttribute
.)
这篇关于list [i]是C#中list.get_item(i)的别名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!