Questions tagged [linq]

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, although ports exist for Java, PHP, JavaScript and ActionScript.

Description is taken from Wikipedia:

LINQ defines a set of method names (called standard query operators, or standard sequence operators), along with translation rules from so-called query expressions to expressions using these method names, lambda expressions and anonymous types. These can, for example, be used to project and filter data into arrays, enumerable classes, XML (LINQ to XML), relational databases, and third party data sources. Other uses, which use query expressions as a general framework for composing readable arbitrary computations, include the construction of event handlers or monadic parsers.

88 questions
92
votes
5 answers

for vs. foreach vs. LINQ

When I write code in Visual Studio, ReSharper (God bless it!) often suggests me to change my old-school for loop in the more compact foreach form. And often, when I accept this change, ReSharper goes a step forward, and suggests me to change it…
beccoblu
  • 1,021
  • 1
  • 8
  • 3
60
votes
11 answers

Why is the use of abstractions (such as LINQ) so taboo?

I am an independent contractor and, as such, I interview 3-4 times a year for new gigs. I am in the midst of that cycle now and got turned down for an opportunity even though I felt like the interview went well. The same thing has happened to me a…
Matt Cashatt
  • 3,315
  • 5
  • 24
  • 35
43
votes
13 answers

Is it unreasonable to expect Any() *not* to throw a null reference exception?

When you create an extension method you can, of course, call it on null.But, unlike an instance method call, calling it on null doesn't have to throw a NullReferenceException -> you have to check and throw it manually. For the implementation of the…
thisextendsthat
  • 535
  • 1
  • 5
  • 11
43
votes
10 answers

Does the usage of LINQ and Lambda Expressions lead to less readable code?

I'm having a discussion with a co-worker on Linq, I'll copy here: Co-Worker: Lets be honest here. Linq syntax sucks. It's confusing and non-intuitive. Me: oh come on, more confusing than T-SQL? Co-Worker: uh, yes. Me: it has the same basic parts,…
BlackICE
  • 2,425
  • 1
  • 18
  • 24
24
votes
9 answers

LINQ Style preference

I have come to use LINQ in my every day programming a lot. In fact, I rarely, if ever, use an explicit loop. I have, however, found that I don't use the SQL like syntax anymore. I just use the extension functions. So rather then saying: from x in…
Erin
  • 2,368
  • 3
  • 19
  • 23
21
votes
3 answers

What is the reasoning behind naming of the .NETs Select (Map) and Aggregate (Reduce)?

In other programming languages, I have seen Map and Reduce, and those are cornerstones of functional programming. I could not find any reasoning or history why LINQ has Aggregate (same as Reduce) and Select (same as Map)? Why I am asking is that it…
Tx3
  • 365
  • 2
  • 8
20
votes
6 answers

What advantage was gained by implementing LINQ in a way that does not cache the results?

This is a known pitfall for people who are getting their feet wet using LINQ: public class Program { public static void Main() { IEnumerable originalCollection = GenerateRecords(new[] {"Jesse"}); var newCollection =…
Panzercrisis
  • 3,145
  • 4
  • 19
  • 34
18
votes
1 answer

Unit tests: deferred assertions with Linq

Is it ok to add deferred assertions like this var actualKittens = actualKittens.Select(kitten => { Assert.IsСute(kitten); return kitten }); Why? So I can iterate just once even with statements expecting materialized collection for…
SerG
  • 482
  • 3
  • 12
17
votes
5 answers

MVC, WCF, EF, LINQ - Is it just me?

...or are things getting more complicated? It seems to me that you need to know a lot of stuff to 'properly' develop an MS web app these days. In the bad old days when we didn't know any better we had database tables, ASP.NET, ADO.NET and you…
Journeyman
  • 337
  • 3
  • 7
17
votes
5 answers

XSLT and possible alternatives

I had a look at XSLT for transforming one XML file into another one (HTML, etc.). Now while I see that there are benefits to XSLT (being a standardized and used tool) I am reluctant for a couple of reasons XSLT processors seem to be quite huge /…
wirrbel
  • 3,018
  • 2
  • 21
  • 33
17
votes
7 answers

What's the best Java equivalent to Linq?

Are there any libraries in Java that come close to providing the functionality of Linq?
rdasxy
  • 3,323
  • 7
  • 29
  • 41
16
votes
8 answers

Senior Interview LINQ questions

I'm preparing a LINQ section in interview questions for senior programmers. What are the most interesting questions in LINQ to include? And why?
Maged Samaan
  • 271
  • 1
  • 2
  • 7
13
votes
4 answers

Is linq more efficient than it appears on the surface?

If I write something like this: var things = mythings .Where(x => x.IsSomeValue) .Where(y => y.IsSomeOtherValue) Is this the same as: var results1 = new List(); foreach(var t in mythings) if(t.IsSomeValue) …
ConditionRacer
  • 5,682
  • 6
  • 38
  • 56
13
votes
1 answer

Why is imperative programming preferred over functional programming?

Background: I am proponent of functional programming who works at a VB.NET shop where the prevailing mental model is imperative programming. Being that foundation of our system is WinForms I can understand we're not going to get entirely away from…
12
votes
5 answers

LINQPad still being used much out there?

I'm trying to guage how popular and how used LINQPad is today. I'm just wondering if it's still a useful tool or not as VS and other tools have gotten better. Furthermore, I am coding over LLBGen by working with LINQ to SQL. I see there is a…
WeDoTDD.com
  • 507
  • 1
  • 4
  • 12
1
2 3 4 5 6