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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:50:47+00:00 2026-05-23T12:50:47+00:00

I have a List object which contains Id values for example it contains: 1,2,10,1,23,11,1,4,2,2,..

  • 0

I have a List object which contains Id values for example it contains:
1,2,10,1,23,11,1,4,2,2,.. etc I need to find out how many times “1”,”2″,… etc have occured
using Linq in C#

kindly help.

  • 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-23T12:50:47+00:00Added an answer on May 23, 2026 at 12:50 pm

    That’s pretty simple using Enumerable.GroupBy:

    var grouped = list.GroupBy(x => x);
    
    foreach (var group in grouped)
    {
        Console.WriteLine("{0} appears {1} times", group.Key, group.Count());
    }
    

    Or alternatively:

    var query = list.GroupBy(x => x, (x, g) => new { Key = x, Count = g.Count() }));
    
    foreach (var result in query)
    {
        Console.WriteLine("{0} appears {1} times", result.Key, result.Count);
    }
    

    (The difference is just in when we transform the group into a result, really.)

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

Sidebar

Related Questions

I have a Request object which contains a list of Approvers. An approver has
I have a list of an object which need to be sorted depending on
I have a generic List<MyClass> where MyClass has a property InvoiceNumber which contains values
I have a List which contains a list of objects and I want to
I have an asp.net page which is returning a list of object as a
I have an object of type list from which I wish to use to
I have an object, and I want to list all the selectors to which
I have a list of objects which need to be output 2 items per
I have a Python list with a number of entries, which I need to
I have a generic List (of Foo) which contains n objects of Type Foo.

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.