0

除了语法之外,以下之间是否有任何区别:

Button.TextProperty.PropertyName //(Xamarin.Forms.BindableProperty.PropertyName)

nameof(myButton.Text)

除了个人偏好之外,是否出于其他任何原因偏好其中一个?

4

1 回答 1

2

在实践中,它们将是相同的值。

nameof() 是编译时值,而 Button.TextProperty.PropertyName 不一定。

Button.TextProperty 是具有 PropertyName 属性的静态分配对象。

nameof() 将被编译到源代码中,并且可能是更快的访问,具体取决于您的编译器优化。

于 2017-11-17T16:13:50.953 回答