Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Enumeration with subtypes c#

First of all perhaps this is a problem due to a bad design. Here is my scenario simplified:

I have a class call Day it represent a day of the year, with its date and the "type" of day.

public class Day{
 Date Key;
 TypeDay type;
}

So the day can be a worked day or a holiday one:

public enum TypeDay{
    Work,
    Holiday
}

So far so good, but now holiday days can have subtypes like paidDays and NonPaid days I would need another enum to represent that subtypes or add all subtypes in a single enum (in this example i have 2 days and 2 subtypes but in real live i have 50-40 types) so this get so messy .

 public enum TypeDay{
        Work,
        Holiday_NonPaid
        Holiday_Paid
    }

How can i build this in a better way,any ideas?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Enumerators didn't support that behaviour, If you feel that a structure like that is needed you can 'simulate' it with a static class

static class TypeDay
{
    public const int Work = 0;

    public static class Holiday
    {
        public const int Paid = 1;
        public const int NonPaid = 2;
    }
}
over 4 years ago · Santiago Trujillo Report

0

You could use flags to treat 'paid' and 'holiday' as independent properties of the enum:

[Flags]
public enum TypeDay{
        Na = 0,
        Work = 1,
        Holiday = 2,     
        Holiday_NonPaid = Holiday,
        Holiday_Paid = Holiday | Work 
    }

This assumes a workday is paid. This lets you either check the exact type, or if the day has a specific flag, isHoliday = type.HasFlag(TypeDay.Holiday) or isPaid = type.HasFlag(TypeDay.Work).

But there are other approaches, like using classes instead of enums.The most appropriate approach will depend on the exact use case and what you want to do with the values.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!