我正在尝试做以下事情:
GetString(
inputString,
ref Client.WorkPhone)
private void GetString(string inValue, ref string outValue)
{
if (!string.IsNullOrEmpty(inValue))
{
outValue = inValue;
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个编译错误.我认为我很清楚我想要实现的目标.基本上我想GetString将输入字符串的内容复制到WorkPhone属性Client.
是否可以通过引用传递属性?
如果在C#自动属性中必须获取和设置get和set,为什么我必须打扰指定"get; set;" 什么?
使用MVVM Light创建了一个项目.ViewModels通常有很多看起来像这样的属性
class TestModel
{
public string DisplayValue { get; set; }
}
class TestViewModel : ViewModelBase
{
public string DisplayValue
{
private TestModel model = new TestModel();
get
{
return model.DisplayValue;
}
set
{
if (model.DisplayValue != value)
{
model.DisplayValue = value;
RaisePropertyChanged();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有时,该属性不在模型中,而是由本地私有字段支持.这种方法工作正常,但有大量的样板代码.如何减少代码重复?
有没有比我提出的解决方案更好的解决方案,还是我错过了MVVM Light内置的东西?
我的方法看起来像
static Node _root = null;
static void AddToTree(int val)
{
AddToTree(val, ref _root);
}
static void AddToTree(int val, ref Node root)
{
if(root == null)
root = new Node() { Val = val };
Node left = root.Left, right = root.Right;
if(root.Val > val)
AddToTree(val, ref left);
else if(root.Val < val)
AddToTree(val, ref right);
}
Run Code Online (Sandbox Code Playgroud)
我怎么看它失败的是我跑
int[] vals = { 2, 1, 5, 3, 8 };
foreach(int i in vals)
AddToTree(i);
Print();
Run Code Online (Sandbox Code Playgroud)
哪个使用
static void Print()
{
if(_root == …Run Code Online (Sandbox Code Playgroud)