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 6380197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:14:12+00:00 2026-05-25T02:14:12+00:00

How do I get all possible pairs of items in a list (order not

  • 0

How do I get all possible pairs of items in a list (order not relevant)?

E.g. if I have

var list = { 1, 2, 3, 4 };

I would like to get these tuples:

var pairs = {
   new Tuple(1, 2), new Tuple(1, 3), new Tuple(1, 4),
   new Tuple(2, 3), new Tuple(2, 4)
   new Tuple(3, 4)
}
  • 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-25T02:14:13+00:00Added an answer on May 25, 2026 at 2:14 am

    Slight reformulation of cgeers answer to get you the tuples you want instead of arrays:

    var combinations = from item1 in list
                       from item2 in list
                       where item1 < item2
                       select Tuple.Create(item1, item2);
    

    (Use ToList or ToArray if you want.)

    In non-query-expression form (reordered somewhat):

    var combinations = list.SelectMany(x => list, (x, y) => Tuple.Create(x, y))
                           .Where(tuple => tuple.Item1 < tuple.Item2);
    

    Both of these will actually consider n2 values instead of n2/2 values, although they’ll end up with the correct answer. An alternative would be:

    var combinations = list.SelectMany((x, i) => list.Skip(i + 1), (x, y) => Tuple.Create(x, y));
    

    … but this uses Skip which may also not be optimized. It probably doesn’t matter, to be honest – I’d pick whichever one is most appropriate for your usage.

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

Sidebar

Related Questions

I would like to be able to get a list of all possible files
I would like to get all possible available currencies. Java 7 had provided such
I'd like to generate all possible pairs of pairs from a list, with the
Is it possible to get all/latest tweets from twitter public list? Example list: https://twitter.com/#!/thecaucus/u-s-senate
Hi how can i get a mapped list to print all possible combinations say
I have an application which forms all the possible pairs and then compare the
I need to split a list into a list of all possible tuples, but
Is there a way to get all possible values from a MySQL enum column?
Is it possible to get all 7 days for a given date using linq
Is it possible to get all div's within a page using jQuery including nested

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.