我需要从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)
}
我不是为什么会引入这样的错误。