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

321
Visualizações
How to remove an enum item from an array

In C#, how can I remove items from an enum array?

Here is the enum:

public enum example
{
    Example1,
    Example2,
    Example3,
    Example4
}

Here is my code to get the enum:

var data = Enum.GetValues(typeof(example));

How can I remove Example2 from the data variable? I have tried to use LINQ, however I am not sure that this can be done.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You cannot remove it from the array itself, but you can create a new array that does not have the Example2 item:

var data = Enum
    .GetValues(typeof(example))
    .Cast<example>()
    .Where(item => item != example.Example2)
    .ToArray();
over 4 years ago · Santiago Trujillo Relatório

0

I have tried to use LINQ, however I am not sure that this can be done.

If you just want to exclude Example2

var data = Enum
    .GetValues(typeof(example))
    .Cast<example>()
    .Where(item => item != example.Example2);

If you want to exclude two or more enums

var data = Enum.GetValues(typeof(example))
    .Cast<example>()
    .Except(new example[] { example.Example2, example.Example3 });
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