Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda