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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:04:08+00:00 2026-05-23T05:04:08+00:00

I want to filter the objects that I have by their topic. I have

  • 0

I want to filter the objects that I have by their topic.

I have many topics: Arts, Economics, Business, Politics. Each topic is a property within the object that I try to classify from a list of those objects.

Here is part of my objects:

public class AllQuestionsPresented
{
    public string Name{ get; set; }
    public string ThreadName { get; set; }
    public string Topic { get; set; }
    public string Subtopic { get; set; }
    public int Views { get; set; }
    public int Replies { get; set; }
    public int PageNumber { get; set; }
    public DateTime Time { get; set; }
    // snip

I created many of those objects feed their properties with different values and put them into a List:

List<AllQuestionsPresented> forumData;

Now I want to group them all into linq by their topics..

var groupedByPages =
    from n in forumData
    group n by forumData
    select .....

Basically i dont know how to continue cause i am not used to deal with linq.. what i want to get is some dictionary..

Dictionary<string,AllQuestionsPresented> dictionary..

If i dont use linq, and add to a dictionary every topic, it will put several “AllQuestionsPresented” objects with the same topic..which will throw an exception..so i have to use group by..but dont know how to achieve that manipulation

  • 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-23T05:04:09+00:00Added an answer on May 23, 2026 at 5:04 am

    You can just call ToDictionary. The parameters are a function to select the keys and another to select the values:

    var groupedByPages =
        from n in forumData
        group n by n.Topic;
    
    IDictionary<string, IEnumerable<AllQuestionsPresented>> dictionary = 
        groupedByPages.ToDictionary(x => x.Key, x => x.AsEnumerable());
    

    But if all you need from the IDictionary interface is the indexing operation, it’s easier to just use a ILookup:

    ILookup<string, AllQuestionsPresented> groupedByPages = forumData.ToLookup(x => x.Topic);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects that I want to filter by an integer
I have a before_create filter that checks if people are posting too many comments.
I want to perform a filter on a model and return all objects that
I want to filter based on an attribute called level. Where I have written
I have several controllers that require a correct user for their edit/update/delete actions. What
I want to represent clubs which have multiple members (each member can also join
We have a hosted application that manages pages of content. Each page can have
I have a hierarchical list of objects. Assume that the structure is as follows:
I have a list of Person s each which have multiple fields that I
I have a web form that uses AD to authenticate users. I want to

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.