在方法中返回查询。 [英] Return query in a method.
问题描述
我有一个查询,我将其保存在 var 但我无法退回。
Hi, I have a query and I save it in a var but I can't return it.
我需要返回查询,因为我在其他方法中使用foreach。
I need return the query because I use a foreach in other method.
查询+方法
公共对象MiMethod(){
返回加入
}
问题是"对象"返回。我不能用它。
The problem is the "object" return. I can't use it.
感谢您的帮助!
推荐答案
为此类数据定义一个特殊类,例如:
类MyClass
{
汽车;
跨度>列表与LT; CarPerson> carPerson;
人员;
}
Class MyClass
{
Car car;
List<CarPerson> carPerson;
Person person;
}
< span lang ="EN-US"style ="margin:0px"> 使用相应的类型。
然后调整最终部分:
选择新的MyClass {car = c,carPerson = cp.ToList(),person = p})。ToList();
select new MyClass { car = c, carPerson = cp.ToList(), person = p }).ToList();
除了上述更改,您还可以尝试
动态类型:
公共动态MiMethod() {
跨度>。 。 。 }
public dynamic MiMethod() { . . . }
然后调用者可以访问
Car , CarPersons 和 Person 成员(虽然没有IntelliSense)。
Then the caller can access the Car, CarPersons and Person members (without IntelliSense though).
这篇关于在方法中返回查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!