I am wondering why would C# provide the lambda expression if it is a performance killer?
Trying to run the following:
Stopwatch sw = new Stopwatch();
sw.Start();
x = x.Select((int i) => i += 1).ToArray();
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
AND
Stopwatch sw = new Stopwatch();
sw.Start();
for (int j = 0; j < 1000; j++) y[j] += 1;
sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
for x = 1000, we would find huge difference.
Is there an appropriate use case for lambda?
I think we must remember LINQ is a language for QUERIES. of course, you can do other stuff with it, as well, such as updating a collection (a how to do asked very often on SO) or running a loop, but why would you do this? LINQ and lambda expressions are not a new, total replacment of procedural programming, its merely a tool which can be used when suitable.
As other query languages (such as t-sql), LINQ provides you the tools to define WHAT you want to get, and not HOW you want to get it, which also allows you to create a language – independant queries, that you can later parse to whatever you want. It may be very convinient and generic to use in many cases, and also can abstract the underlying data types/data sources, but it also means you leave the concrete implementation of HOW to get whay you asked for to whoever wrote the parser for your queries.
I suggest you read about some sample linq providers out there. Take a look at LINQ to LDAP for example: such providers allow you, as a develoepr, to concentrate only on the data you want, and not on the underlying data structure/Active Directory API, which can be pretty annoying to use.
As with every other tool you get, you need to ask yourself what you want to get, and if this tool is the best way to go. A good analogy would be using loops in sql servre query; Of course, it can be done, but you will usually prefer to build a select which will let the sql engine to decide HOW to execute your query.