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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:45:21+00:00 2026-05-16T18:45:21+00:00

You may have run into situations wherein you declare a certain enum and you

  • 0

You may have run into situations wherein you declare a certain enum and you want to evaluate a certain object to find out which enum categories it satisfies i.e an object may satisfy the conditions for it to be classified into more than one enum.

An example would be, say in an university i have various Course and this has the list of students attending from different specialization attending the same.
Thus we have

public class Course
{
    int Id;
    IList<Electrical> ElectricalStudents;
    IList<Computer> ComputerStudents;
    IList<Bioengineering> BioengineeringStudents;
    IList<Mechanical> MechanicalStudents;
}

and my enum is as follows

public enum ParentDepartment
{
    Electrical,
    Mechanical,
    Biology
}

and for every course object I have I need to identify which parentdepartments the students fall into so that I can use them appropriately( so that i can mail those respective departments)

How would you handle such a case? What is the best way to go about the same.

The way i can think of is have a static function on Course object whose definition is something like this

public static IList<ParentDepartment> GetParentDepartments(Course course)
{
    public parentDepartmentList=new List<ParentDepartment>();
    if(ElectricalStudents.Count>0)
            Add(parentDepartmentList,ParentDepartment.Electrical);
    if(ComputerStudents.Count>0)
            Add(parentDepartmentList,ParentDepartment.Electrical);
    if(MechanicalStudents.Count>0)
            Add(parentDepartmentList,ParentDepartment.Mechanical);
    if(BioengineeringStudents.Count>0)
            Add(parentDepartmentList,ParentDepartment.Biology);
}

private void Add(IList<ParentDepartment> parentDepartmentList,ParentDepartment         parentdept)
{
    if(!parentDepartmentList.Contains(parentdept))
            parentDepartmentList.Add(parentdept);
}

Hope the things are clear. Please note this an hypothetical model and please avoid giving me solution like changing the model.

Any improvement to the functions is also greatly appreciated. I just dont like the way things have been impelemented here. Is there a leaner and better method to handle the same?

Any answer is greatly appreciated.

P.S: Sorry for making this C# specific but I think the concept can be extended over to any language. Thanks

  • 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-16T18:45:22+00:00Added an answer on May 16, 2026 at 6:45 pm

    In .NET, sets of enum values are usually realized using a Flags enumeration:

    [Flags]
    public enum ParentDepartments
    {
        None = 0x0,
        Electrical = 0x1,
        Mechanical = 0x2,
        Biology = 0x4,
    }
    
    public static ParentDepartments GetParentDepartments(Course course)
    {
        var departments = ParentDepartments.None;
    
        if (course.ElectricalStudents.Any())
            departments |= ParentDepartments.Electrical;
    
        if (course.ComputerStudents.Any())
            departments |= ParentDepartments.Electrical;
    
        if (course.MechanicalStudents.Any())
            departments |= ParentDepartments.Mechanical;
    
        if (course.BioengineeringStudents.Any())
            departments |= ParentDepartments.Biology;
    
        return departments;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file which may have empty or blank rows. I want
I have a script that may be run manually or may be run by
I have this relatively large numerical application code that may run for a few
if i have a php background job, may need to run 4-5hours or more
I have a multidimensional points which may have keys of the following 3 types
I have to add functionality to an existing application and I've run into a
There's a bit of code which writes data to a MemoryStream object directly into
I am mucking about with WPF glyphs and documents and have run into a
I seem to have run into a strange bug or more likely some setting
We are using Typescript 0.8.1.0, and we have run into a situation where Visual

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.