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

The Archive Base Latest Questions

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

Working on a .net 2.0 project and no linq and cannot add any external

  • 0

Working on a .net 2.0 project and no linq and cannot add any external library.

Build a small example of what I need to do in my real project.

How do you group by eg “Employee.Category” without using linq.

For each group I need to do something about it.

How do you group by in .net 2.0?

     class Program
        {
            static void Main(string[] args)
            {
                List<Employee>employees=new List<Employee>();
                Employee employee = new Employee();
                employee.Id = 1;
                employee.Category = "Management";

                Employee employee2 = new Employee();
                employee.Id = 2;
                employee.Category = "Management";

                Employee employee3 = new Employee();
                employee.Id = 3;
                employee.Category = "Director";

                Employee employee4 = new Employee();
                employee.Id = 4;
                employee.Category = "Worker";

                Employee employee5= new Employee();
                employee.Id = 5;
                employee.Category = "Director";
                Employee employee6 = new Employee();
                employee.Id = 6;
                employee.Category = "Worker";

                employees.AddRange(new Employee[] { employee, employee2, employee3, employee4, employee5, employee6 });

                //1)Group them by category in .net 2.O NO LINQ
                //2)Foreach item in the group do something.

                Console.WriteLine("??");
            }
        }

        public class Employee
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string Category { get; set; }
        }

Thanks for any suggestions

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

    How about:

    Dictionary<string, List<Employee>> groups =
           new Dictionary<string, List<Employee>>();
    foreach(Employee emp in employees) {
        List<Employee> group;
        if(!groups.TryGetValue(emp.Category, out group)) {
            group = new List<Employee>();
            groups.Add(emp.Category, group);
        }
        group.Add(emp);
    }
    
    foreach(KeyValuePair<string,List<Employee>> pair in groups) {
        Console.WriteLine(pair.Key);
        foreach(Employee emp in pair.Value) {
            Console.WriteLine(emp.Id);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a personal project (C# / ASP.NET) that will use LINQ to
I'm working on a .NET project that integrates with an external company. This company
I am working with asp.net website project that some of pages need authentication. I
I need to use linq in C# Windows form application working with .Net Framework
I am working on asp.net project and each time i need to use jquery
I've been working with the xml.linq classes in .net recently. But may need to
When working in a VB.NET project in Visual Studio (2008 specifically, but hopefully the
I'm working on a C#/ASP.NET project that has all the javascript files in a
I am working on an ASP.NET project which is physically located at C:\Projects\MyStuff\WebSite2. When
I've just started working on an ASP.NET project which I hope to open source

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.