除语法外,之间存在任何的区别:
Button.TextProperty.PropertyName //(Xamarin.Forms.BindableProperty.PropertyName)
和
nameof(myButton.Text)
除个人偏好外,是否有人优先于其他原因?
答案 0 :(得分:2)
在实践中,它们将具有相同的价值。
nameof()是编译时的值,而Button.TextProperty.PropertyName则不一定。
Button.TextProperty是一个静态分配的对象,具有PropertyName属性。
nameof()将被编译到源代码中,并且可能是更快的访问权限,具体取决于您的编译器优化。