When a hammer works, why by a pneumatic wrench?
I am not sure there is much overhead in LINQ, but performance is not the
only reason you use one programming construct over another. There is also
clarity of code (a maintainability issue). If you can use a simple if, I am
not sure iffing with LINQ is your best option.
LINQ is best when you have a set you need to filter, etc. It is great at
manipulating objects that conform to IEnumerable. While you can create
objects holding simple types, and then iterate, why add the extra complexity
to the code?
Just my two cents.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"Mythran" <My*****@community.nospamwrote in message
news:C1**********************************@microsof t.com...
Consider the following:
List<intints = new List<int>();
for (int i = 0; i < 20; i++) {
ints.Add(i);
}
// EXAMPLE 1
var strings =
from i in ints
where i 0 && i < 10 select i.ToString();
foreach (string s in strings) {
Console.WriteLine(s);
}
// EXAMPLE 2
foreach (int i in ints) {
if (i 0 && i < 10) {
Console.WriteLine(i.ToString());
}
}
Now, what kind of overhead are we looking at for using LINQ in EXAMPLE 1
compared to using just the 'if' statement as shown in EXAMPLE 2? I have
multiple code blocks that I've redone to use LINQ and have started
thinking if I shouldn't have when a simple 'if' statement would do the
trick just fine....what do you peeps think?
Thanks a bunch!
Mythran
::I'm NOT a zero, I'm a one (just don't ask my wife)::