从ObservableCollection中检索项目并将它们添加到List<>中在c#中

时间:2016-09-07 11:41:48

标签: c#

我需要从ObservableCollection中检索项目并将其添加到List<>变量,我按照以下方式进行 -

public class getEmployeewiseRecord
    {
        public List<string> uid { get; set; }
        public string fromdate { get; set; }
        public string todate { get; set; }
    }
public  class empList_Model
    {
        public string empName{ get; set;}
        public Boolean check{ get; set;}            
        public string id{ get; set;}
    }   

我有上面的模型,我创建了一个getEmployeewiseRecord类型的对象,并设置其值如下所示 -

ObservableCollection<empList_Model> generateEmpList = new ObservableCollection<empList_Model>();       


    obj = new getEmployeewiseRecord ();
    obj.fromdate = fromDatePicker.Date.ToString();
    obj.todate = toDatePicker.Date.ToString ();
    foreach (empList_Model user in generateEmpList) {
                    obj.uid.Add ("user.id.ToString()");//Error : Object reference is not set to an instance of object(app crashes)
                }

我不是为什么会引入这样的错误。

0 个答案:

没有答案