LINQ is extremely powerful and can be used highly in code. But is it best practice to use it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a good idea to use it when it makes the code clearer and simpler to maintain, and when you’re not in any of the situations where the performance of LINQ is too slow for your needs.
You haven’t specified whether you’re talking about LINQ to Objects or LINQ to SQL etc, but I know there are situations where the latter has proved too slow for some high traffic sites, and they’ve moved off it… but only after it’s been shown to be an issue. LINQ to Objects will often have a very small performance hit compared with “hard-coding” the same logic, but that’s even less likely to be a real problem.
Of course LINQ can certainly be overused, and I’ve seen people reaching for a LINQ solution when there are far more appropriate ways of achieving the same thing – so don’t try to use it everywhere you possibly can. Just use it where it clearly helps.