如果类类型列表中有一个名为2泛型列表分配
Collection<PurchaseOrderDetail> poDetails = new Collection<PurchaseOrderDetail>();
,并与同类型的另一个列表是有一个名为_poH.PODetail
为什么_poH.PODetail = poDetails.ToList();
产生
无法隐式转换类型错误'System.Collections.Generic.List' to'System.Collections.ObjectModel.Collection'
什么是这个解决方案,请任何解释。
所有的问题背后的原因是
_poH.PODetail = poDetails;
做出poDetails.RemoveAt(Convert.ToInt32(e.RowIndex));
更新以及所以我)寻找像_poH.PODetail = poDetails.ToCollection一些事情(;
因为'Collection'不是基输入'List' –
继续编辑:这是因为'Collection'是一个引用类型,就像大多数类型都在.NET中一样。任何使用这种类型的变量或类型成员实际上都是指向一个实例。这意味着除非'PurchaseOrderDetail'是一个'struct'(它是值类型),否则你在一个属性中改变的任何属性都将反映在它所在的任何集合中,即使存在许多实际实例甚至种类集合。 –
Crono