【问题标题】:Copying object to another object but remove certain properties Windows Phone 8将对象复制到另一个对象但删除某些属性 Windows Phone 8
【发布时间】:2013-03-18 21:20:34
【问题描述】:

我想将一个对象复制到另一个对象,但删除某些属性。例如

public  class A
{
    public bool IsResizeCancel { get; set; }
    public double MaxSliderValue { get; set; }
    public double CurrentWidth { get; private set; }
    public double CurrentHeight { get; private set; }
}

将对象 A 复制到对象 B,但删除 CurrentWidth 和 CurrentHeight 属性

public class B
{
    public bool IsResizeCancel { get; set; }
    public double MaxSliderValue { get; set; }
}

如何用最少的代码高效地做到这一点?

【问题讨论】:

    标签: c# object copy windows-phone-8 clone


    【解决方案1】:
    public class B
    {
        public B(A a)
        {
            IsResizeCancel = a.IsResizeCancel;
            MaxSliderValue = a.MaxSliderValue;
        }
        public bool IsResizeCancel { get; set; }
        public double MaxSliderValue { get; set; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 2010-10-29
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多