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

320
Views
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 answers
Answer question

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 Report

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 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!