相关疑难解决方法(0)

在C#中通过引用传递属性

我正在尝试做以下事情:

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# properties pass-by-reference

214
推荐指数
4
解决办法
11万
查看次数

C#自动属性 ​​- 为什么我要写"get; set;"?

如果在C#自动属性中必须获取和设置get和set,为什么我必须打扰指定"get; set;" 什么?

c# automatic-properties c#-3.0

44
推荐指数
5
解决办法
4万
查看次数

提高财产的更好方法改变了MVVMLight

使用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内置的东西?

c# wpf mvvm

3
推荐指数
1
解决办法
5032
查看次数

我的算法中将节点添加到二叉树的缺陷在哪里?

我的方法看起来像

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)

c# algorithm data-structures

2
推荐指数
1
解决办法
63
查看次数