tags:

views:

85

answers:

1

Hey,

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.

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.: Don't care about type, I will cast it back easily:

List<User> user; user = (List<User>)MethodName(user);
+3  A: 

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)
Jon Skeet
One question: I cannot do a ".Where" in the IList, why?
Kovu
@Kovu: Because it's not strongly typed. All the LINQ extension methods (other than OfType and Cast) are on `IEnumerable<T>`.
Jon Skeet
I tried with IEnumeravble replace the IList in the method call, but nothing. How can I do this so generic, that I can use the ".Where" in the list?
Kovu
I showed you with the second method declaration - make it a generic method.
Jon Skeet
Perfect! I don't get it, sry-
Kovu