Passing an empty IEnumerable argument to a method
Posted
by avance70
on Stack Overflow
See other posts from Stack Overflow
or by avance70
Published on 2010-05-05T13:12:42Z
Indexed on
2010/05/05
13:18 UTC
Read the original article
Hit count: 306
I have this method (simplified):
void DoSomething(IEnumerable<int> numbers);
And I invoke it like this:
DoSomething(condition==true?results:new List<int>());
The variable results is formed with a LINQ select condition (IEnumerable).
I was wondering is this List<int>() the best way (the fastest?) to pass an empty collection, or is new int[0] better? Or, something else would be faster, a Collection, etc.? In my example null wouldn't be ok.
© Stack Overflow or respective owner