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.
You could also use a static method reference: roles. removeIf(Role. SYSTEM_ADMIN::equals);
To iterate through an enumeration, you can move it into an array using the GetValues method. You could also iterate through an enumeration using a For... Each statement, using the GetNames or GetValues method to extract the string or numeric value.
Iterate over Enum Values: There are many ways to iterate over enum values: Iterate Using forEach() Iterate Using for Loop. Iterate Using java.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With