Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:03:21+00:00 2026-05-26T18:03:21+00:00

John Skeets answer to this question, Select all unique combinations of a single list,

  • 0

John Skeets answer to this question, Select all unique combinations of a single list, with no repeats, using LINQ, works awesomely.

However, can someone break down component by component the inner workings of how the first answer is working:

List<int> slotIds = new List<int> {1, 2, 3};
var query = slotIds.SelectMany((value, index) => slotIds.Skip(index + 1),
                              (first, second) => new { first, second });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:03:22+00:00Added an answer on May 26, 2026 at 6:03 pm

    It’s roughly equivalent in concept to this, although the actual execution model is different of course (lazy etc):

    for (int i = 0; i < slotIds.Count; i++)
    {
        int first = slotIds[i];
        for (int j = i + 1; j < slotIds.Count; j++)
        {
            int second = slotIds[j];
            results.Add(new { first, second });
        }
    }
    

    The SelectMany taking a projection from value and index is a way of using both first and i to make an inner loop. We need the index so that we can skip index + 1 values, which is equivalent to the j loop starting at i + 1 in the above code.

    Does that help? If not, could you pinpoint which bit is confusing?

    EDIT: Aargh – I hadn’t realized that the other question you were referring to started out with this code! I think it’s still useful though, to give the paragraph below something to hang on…

    If you understood the alternative (query expression) version of my answer, then the first version is similar, just using an overload of SelectMany which allows you to use both the value and index in the “outer” sequence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am posting this question anew at the behest of the distinguished Mr. John
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
list = [['John',3]['Carey',4]['Jake',3]] I'm looking for a way to select the data of a
I am using John resig's implementation class mentioned here: http://ejohn.org/blog/simple-javascript-inheritance/ Now I have a
I have a table like this: name code group john 12 smith 15 how
While John Resig's recommendation is, quite rightly, to declare all events within a jquery.document.ready()
I would like to combo gWidgets(john verzani) with Rgtk2. This could be used by
I was reading John Resig's Secrets of JavaScript Ninja and saw this code: function
DB: Sql Server 2008. I have a really (fake) groovy query like this:- SELECT
I've been using John Resig's getStyle function from Pro JavaScript Techniques to get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.