Linq到通用列表? [英] Linq to generic list?
本文介绍了Linq到通用列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的DAL中,我有3-5个列表:
in my DAL I have 3-5 Lists of something:
List<User>, List<Items>, List<bla>
现在,我想在方法中修改这些通用列表.
Now I want to modify these Lists generic in a method.
如何编写带有所有这些参数允许的方法? (我尝试使用var,但方法头不允许这样做)
How can I write a method with parameters allowed of all of this? (I tried var but don't allowed in the method head)
P.s .:不在乎类型,我会很轻松地将其退回:
P.s.: Don't care about type, I will cast it back easily:
List<User> user; user = (List<User>)MethodName(user);
推荐答案
您的问题有些含糊,但我怀疑您正在寻找:
Your question is somewhat vague, but I suspect you're looking for:
void SomeMethod(IList list)
如果您实际上是在方法中更改列表,则不需要返回值.
If you're actually changing the list within the method, you don't need a return value.
另一种方法(坦率地说,更好)是使方法通用:
An alternatively (a nicer one, frankly) is to make the method generic:
void SomeMethod<T>(IList<T> list)
这篇关于Linq到通用列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文