Reputation: 4270
Upvotes: 32
Views: 21698
Reputation: 1500675
I'm a massive fan of LINQ - although it needs to be kept in perspective, and not treated as a silver bullet.
Pros:
Cons:
OrderBy
for things other than ordering - e.g. finding the item with the maximum value of a propertyI find it's best when dealing with in-process queries. They're easy to predict, understand and extend. Complementary technologies like LINQ to XML and Parallel LINQ are great. LINQ to Objects can be used almost anywhere.
LINQ to SQL etc are really nice where they're appropriate, but they're harder to understand and need more expertise. They're also only applicable in certain areas of your code.
Upvotes: 36
Reputation: 25099
Pro:
Con:
@Jon Skeet - another great response, you steal everyones thunder :P. I totally agree about how hard writing a provider is, I'm in the process of it at the moment! Are you familiar with Bart De Smet? He's got lot of good examples of doing so.
Upvotes: 2
Reputation: 13723
I've used LINQ mainly to work on collection of objects. LINQ works wonderfully with object collections, removing the need of predicate functions in most cases.
I tried using LINQ to SQL a little while ago, but found it underpowered and clumsy. In particular I couldn't bring myself to use the SQL Database class designer. Maybe it does give intellisense on the database, but who needs it when you've got SQL?
Let me tell you though, it's certainly a good idea to learn more about LINQ, as the applications in the future should only increase.
Upvotes: 1
Reputation: 2353
There is a problem with them of sneaking exceptions out of try catch blocks by way of delayed execution.
for example:
var l = new List<int>() {1, 2, 3};
try
{
l.Select(x => x / 0);
}
catch
{
// error
}
l.elementAt(0); // exception occurs here outside of the try catch
Which can be tricky the first time you run into it, especially as the debugger will point you at the code inside the try-catch.
Otherwise I find them incredibly useful and very time saving.
Upvotes: 4
Reputation: 23226
My favorite part: using them to simplify writing unit tests. Also IEnumerable chains have urged me to write more fluent interfaces in my code.
Cons: Lambdas and extension methods are my hammers and all problems are nails.
Overall: breathed new life into programming in C# for me.
Upvotes: 4