M
Mythran
Consider the following:
List<int> ints = 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)::
List<int> ints = 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)::