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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:28:35+00:00 2026-05-17T00:28:35+00:00

I have List object filled with instances of a custom struct. list.Add(new Mail(mail1, test11,

  • 0

I have List object filled with instances of a custom struct.

        list.Add(new Mail("mail1", "test11", "path11"));
        list.Add(new Mail("mail2", "test12", "path12"));
        list.Add(new Mail("mail1", "test13", "path13"));
        list.Add(new Mail("mail1", "test14", "path14"));
        list.Add(new Mail("mail2", "test15", "path15"));

        var q = from x in list
                group x by x.Sender into g
                let count = g.Count()
                where count > 2
                orderby count descending
                select new { Sender = g.Key};

        foreach (var x in q)
        {
            Console.WriteLine(x.Sender);
        }

The output of that code would be this:

mail1

But since I need to work on every Mail item which is available more than twice (or maybe n-times) based on the value of a certain property (i.e. Sender), I need a query to show me ALL items that occur more often than n (including a reference to the corresponding Mail item.

After filling the query I would love to do something like this:

    foreach (var x in q)
    {
        Console.WriteLine(x.Sender + " - " + x.Path + " - " + x.Count);
    }

I’m new to LINQ but I’m sure this is somehow possible.

Thanks for your help

Regards,
Kevin

  • 1 1 Answer
  • 1 View
  • 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-17T00:28:35+00:00Added an answer on May 17, 2026 at 12:28 am

    Include the properties to be added to your anonymous type.

    var q = from x in list
            group x by x.Sender into g
            let count = g.Count()
            where count > 2
            orderby count descending
            select new
            {   // add your fields here
                Sender = g.Key,
                Path = ...,      // not sure what you wanted here
                Count = count,
                Mails = g,       // include the mails in the group
            };
    

    Then you can do with it what you want.

    foreach (var x in q)
    {
        // each x is a type with the fields
        //     Sender
        //     Path
        //     Count
        //     Mails
        Console.WriteLine(x.Sender + " - " + x.Path + " - " + x.Count);
        foreach (var mail in x.Mails)
        {
            // do something with each individual mail
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have filled List<Object1> Object 1 contain 2 fields (int id & string name)
I have a List<> in my program, filled with my custom class. I want
First array list:- ArrayList<Object> list1; Second array list:- ArrayList<Object> list2; Suppose I have filled
I have a List object and I want to remove the duplicated items but
I have a list object List<Documents> , and inside that I have another list
I have a Generic List object which hold below table as its own value.
I have a list of object, stored in an arrayController and rendered on the
I have a list of object I wish to sort in C#.Net 3.5, the
I have a List of object, produced by JPA q.getResultList() . I would like
I have a list of object that is the data source. Something like that:

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.