C#构造函数传值,变量作用域 5C

//主窗体
``` private void button4_Click(object sender, EventArgs e)
{
/////// DecompositionDataPackage(dataSet, ref measurementMsgs);
if (measureData.Count > 0)
{ measureData.Clear(); }

measureData.Add(OKNG.NG);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.NG);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.NG);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.NG);
measureData.Add(OKNG.NG);
measureData.Add(OKNG.Emptty);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.NG);
measureData.Add(OKNG.OK);
measureData.Add(OKNG.Emptty);
}

    private void button5_Click(object sender, EventArgs e)
    {
        ut = new UTest1(measureData);
    }

  public  List<OKNG> measureInfo = new List<OKNG>();
        public  UTest1( List<OKNG> measureData)
        {
            InitializeComponent();
            if (measureInfo.Count == 0)
            { measureInfo = DeepCopy(measureData); }
            else
            { measureInfo.Clear(); measureInfo = DeepCopy(measureData); }
        }
        public static T DeepCopy<T>(T obj)
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                XmlSerializer xml = new XmlSerializer(typeof(T));
                xml.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                retval = xml.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }


DeepCopy()是尝试着深复制。集合数据传给用户控件,但是用户控件上,并不能接收到值。

1个回答

DeepCopy的代码贴出开看下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问