为Car类编写个构造函数,它接受另一个Car对象作为参数,并复制这个参数的所有属性!

解决方案 »

  1.   

    /// <summary>
    /// Car の概要の説明です
    /// </summary>
    public class Car
    {
        private System.Drawing.Color color;
        private int height;
        private int width; public Car(Car car)
    {
    //
    // TODO: コンストラクタ ロジックをここに追加します
    //
            this.color = car.color;
            this.height = car.height;
            this.width = car.width;
    }
    }
      

  2.   

    public class car
        {
            public string aa = null;
            car(car c)
            {
                foreach (System.Reflection.FieldInfo fi in typeof(car).GetFields())
                { 
                    fi.SetValue(this,fi.GetValue(c);
                }
            }
        }
      

  3.   

    //复制属性和字段
     public class car
        {
            public string aa = null;
            car(car c)
            {
                foreach (System.Reflection.FieldInfo fi in typeof(car).GetFields())
                { 
                    fi.SetValue(this,fi.GetValue(c));
                }            foreach (System.Reflection.PropertyInfo fi in typeof(car).GetProperties())
                { 
                    fi.SetValue(this,fi.GetValue(c));
                }
            }
        }