Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

This question was quickly closed and just as quickly reopened, with two sides both passionate about whether or not it is acceptable for SO.

Request for an example of using LINQ to avoid nested loops

Arguments in favor of closing centered around the notion that it is a "poll" question.

Arguments in favor of not closing (and reopening) centered around the idea that the question seeks specific answers to a fairly narrow question, though certainly the OP is looking for a range of example solutions rather than a specific "best" solution.

Is this question acceptable? What concrete guidance indicates whether it is/isn't?

share|improve this question
Personally, I'd be inclined to close it, as it's subjective as to whether a "best" answer could be chosen, which would be desirable. – Nightfirecat Nov 28 '11 at 23:59
up vote 8 down vote accepted

I saw the question and my instinct was 'poll', but I read the comments and decided to wait and see. I agreed with your comment that the questioner was asking for concrete examples, so I figured it's worth a shot to see what kind of answers the question garners.

My tendency was to agree with Anthony Pegram:

This question is "create an arbitrary problem and then a solution where Linq is useful." This is not an effective SO question. We provide solutions to problems, not ideas for problems that then need a solution. This is a poll, not a question with a single best answer.

However, having read the answers I don't believe that this is a constructive question. Asking for 'examples' of something leads to both duplicate answers (the obvious SelectMany) and incorrect answers (i.e. offtopic, e.g. the GroupBy answer which the questioner notes he already grasps).

The question is too close to being a simple What's good about LINQ? type poll question. I don't understand whether it's serious or just an attempt at making a popular question.

people say you can avoid heavy nested loops by using LINQ, but few LINQ examples come with pre-linq code listings

If the questioner had googled, there are plenty of examples of 'pre-linq code'.

These two, for example, deal with actual problems.

If the questioner had an actual problem then they should ask that question. As it stands, it's just an attempt at starting a discussion.

share|improve this answer

I think your reasoning is dead on.

His wording is a little loose, but at the core he's asking "how can I use Linq to avoid heavily nested loops." Seems specific enough to allow for specific, useful answers... which he got.

Edit the question a little (specifically the title and the last sentence) to avoid the bad impression and I think it would be perfect. Something like:

How can I use LINQ to avoid nested loops?

I have an OK understanding of the LINQ operators and the syntax choices. Problem is, people say you can avoid heavy nested loops by using LINQ, but we usually need a foreach or two to iterate the query anyway.

<would have been good to have an unoptimized example here in the original>

How can I use LINQ to avoid these nested loops?

He can get a real answer, hopefully one that's thorough, and use that to make his own examples. The fact that he needs examples for a presentation isn't relevant.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .