public ObservableCollection<DataModel> DataList { get; set; }
public DataModel SelectedItem { get; set; }
当我这样做时:
SelectedItem = DataList[0]; // its working fine.
但我需要得到与
不同的东西SelectedItem = DataList.Select(x => x.InnNum).Distinct();
但这显示错误
Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to 'DTO.DataModel'. An explicit conversion exists (are you missing a cast?)"
有人可以帮我吗?
如何解决它。 如何在将IEnumerable分配给SelectedItem之前将其转换为模型类型?
答案 0 :(得分:0)
DataList.Select(x => x.InnNum).Distinct()
会为您提供IEnumerable
个string
个对象。
您要将SelectedItem
设置为DataModel
哪个类型{{1}}。因此错误。