如何向 get 添加更多功能;并设置;在 Xamarin 表单中通过删除“=>”并为每个替换为代码块?
How can I add more functionality to a get; and set; in Xamarin forms by removing the "=>" and replacing with a code block for each?
我想更改此代码:
public string Height
{
get => (string)GetValue(HeightProperty);
set => SetValue(HeightProperty, value);
}
如何更改代码以不使用 =>
并在 get 和 set 发生的事情前后添加更多代码行?
您可以使用大括号。
public string Height
{
get
{
<your code>
return (string)GetValue(HeightProperty);
}
set
{
<your code>
SetValue(HeightProperty, value);
<your code>
}
}
您可以在get
和set
之后打开代码块:
public string Height
{
get {
// do something
return (string)GetValue(HeightProperty);
}
set {
// validations, etc...
SetValue(HeightProperty, value);
}
}
我想更改此代码:
public string Height
{
get => (string)GetValue(HeightProperty);
set => SetValue(HeightProperty, value);
}
如何更改代码以不使用 =>
并在 get 和 set 发生的事情前后添加更多代码行?
您可以使用大括号。
public string Height
{
get
{
<your code>
return (string)GetValue(HeightProperty);
}
set
{
<your code>
SetValue(HeightProperty, value);
<your code>
}
}
您可以在get
和set
之后打开代码块:
public string Height
{
get {
// do something
return (string)GetValue(HeightProperty);
}
set {
// validations, etc...
SetValue(HeightProperty, value);
}
}