Xamarin.Forms - Button.TextProperty.PropertyName和nameof(myButton.Text)之间的区别

时间:2017-11-17 16:00:30

标签: c# data-binding xamarin.forms nameof

除语法外,之间存在任何的区别:

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

nameof(myButton.Text)

除个人偏好外,是否有人优先于其他原因?

1 个答案:

答案 0 :(得分:2)

在实践中,它们将具有相同的价值。

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

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

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