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

  • Home
  • SEARCH
  • 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 3997046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:21:13+00:00 2026-05-20T07:21:13+00:00

I am trying to construct a LINQ query that will take a list of

  • 0

I am trying to construct a LINQ query that will take a list of elements, and based on a comparison between the elements in the list, select the ones that meet a certain criteria. Like this:

var subset = set.SomeLinqQuery((e1,e2) => e1 == e2);

subset now contains all e1 of set where e1 == e2. Any ideas? I originally thought of just having a nested loop, but I realized that there must have been a way to do it in LINQ.

  • 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-20T07:21:14+00:00Added an answer on May 20, 2026 at 7:21 am

    You will need a method to generate the unique pairs of items from the original set. Here’s my implementation of that:

    /// <summary>
    /// Returns an enumeration of tuples containing all unique pairs of distinct
    /// elements from the source collection. For example, the input sequence
    /// { 1, 2, 3 } yields the pairs [1,2], [1,3] and [2,3] only.
    /// </summary>
    public static IEnumerable<Tuple<T, T>> UniquePairs<T>(this IEnumerable<T> source)
    {
        if (source == null)
            throw new ArgumentNullException("source");
        return uniquePairsIterator(source);
    }
    private static IEnumerable<Tuple<T, T>> uniquePairsIterator<T>(IEnumerable<T> source)
    {
        // Make sure that 'source' is evaluated only once
        IList<T> arr = source as IList<T> ?? source.ToList();
        for (int i = 0; i < arr.Count - 1; i++)
            for (int j = i + 1; j < arr.Count; j++)
                yield return new Tuple<T, T>(arr[i], arr[j]);
    }
    

    Now you can easily achieve what you wanted:

    var results = set.UniquePairs()
                     .Where(pair => pair.Item1 == pair.Item2)
                     .Select(pair => pair.Item1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to construct a linq query that pulls all nodes that have a
I'm trying to write Linq query on this Products table based on FacetTypes that
H. I'm trying to construct linq query that dynamicly generate query for custom ordering
I'm trying to construct my linq-to-sql expression so that it only generates a single
I'm having issues with a Linq query that will actually do what I need
I am trying to construct a LINQ query, with expression trees, to do the
Im trying to construct a script that will check if a url variable called
I'm trying to use Linq expressions to construct a query, and am stuck trying
Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I'm trying to construct a regular expression that would extract the name of 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.