enum loop 1

enum loop

enum Foos {
  Foo,
  Bar,
}

foreach(Foos val in Enum.GetValues(typeof(Foos))) {
  //Do whatever with the value 😀
}

Here is what the above code is Doing:
1. We’re creating an enum called Foos with two values: Foo and Bar.
2. We’re using the Enum.GetValues method to get all the values of the Foos enum.
3. We’re using a foreach loop to iterate over the values of the Foos enum.

The Enum.GetValues method returns an array of the values of the enum.

The foreach loop iterates over the array of values and assigns each value to the val variable.

The val variable is of type Foos, so we can use it as a Foos enum value.

Similar Posts