对LINQ的问题 [英] Problem on LINQ to object

查看:53
本文介绍了对LINQ的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对实现IEnumerable< T>的对象进行一些查询或排序操作。我更喜欢使用linq,但很快我发现linq会产生新实例的问题。

I need to do some query or sort operations to an object which implements IEnumerable<T>. I prefer to use linq, but soon I found a problem that linq will make new instances.

我的意思是:

我有一个List< ; TClass>包含A,B,C,D然后我对它进行查询操作,当linq表达式返回时,返回值包含A B C D,但它们与原始A B C D不同!似乎linq已经制作了A B C D的新实例,但我需要它是原始的,所以,有没有人知道会发生什么?我该如何防止这种情况?

I have a List<TClass> contains A,B,C,D and then I make a query operation to it, when linq expression returns, the return value contains A B C D, but they're different from the original A B C D! It seems that linq has make new instances of A B C D, but what I need it the original ones, so, does anybody know what happens? How can I prevent this?

推荐答案

你能发布你用过的查询吗?
Can you post the query you used for it?


这篇关于对LINQ的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆