list [i]是C#中list.get_item(i)的别名吗? [英] Is list[i] an alias for list.get_item(i) in C#?

查看:583
本文介绍了list [i]是C#中list.get_item(i)的别名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在传递一个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

其中childListOfObjectsList<someObejct>和,

expression.Body返回o => o.childListOfObjects.get_Item(0).property.

跳到最后:

list[i]是C#中list.get_item(i)的别名吗?

推荐答案

是的,属性通常只是get_PropertyNameset_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

(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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆