Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda