开发者

Assignment between generic lists

How to assign same object list but in different namespace. list, list2

list = list2;

Cannot implicitly convert type System.Collections.Generic.List<namespa开发者_如何学Cce1.MyData> to System.Collections.Generic.List<namespace2.MyData>


This sounds to me like a WCF proxy that has been generated and you want to reuse the existing class libraries instead of the proxy generated ones.

If this is the case, then see this answer or this answer.

Edit:

as a follow up to this, occassionally you may be in the position where you can't reuse the common class definitions (in the case of Silverlight you have to create a whole new assembly which may not be practical). If you are in this position, there is another option: the proxy generated classes are defined as partial, so you can extend them with a Clone() or Copy() method that returns the identical object from the other namespace, with the values copied over.


If the objects can be cast to each other, you can do this, but it is looping though the lists and making a copy, it's not a direct assignment.

var newList = oldList.Cast<NewType>().ToList();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜