Last active
December 6, 2019 06:27
-
-
Save sachintha81/e7d52a133fe3ae97e9e1e260c740885a to your computer and use it in GitHub Desktop.
Loop through Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Typed version | |
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>(); | |
// Helper function | |
public static class EnumUtil { | |
public static IEnumerable<T> GetValues<T>() { | |
return Enum.GetValues(typeof(T)).Cast<T>(); | |
} | |
} | |
// Usage: | |
var values = EnumUtil.GetValues<Foos>(); | |
// For-each | |
foreach(Foos foo in Enum.GetValues(typeof(Foos))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment