Yes you can use the ? GetValue???s
method:
(是的,你可以使用GetValue???s
方法:)
var values = Enum.GetValues(typeof(Foos));
Or the typed version:
(或打字版本:)
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();
I long ago added a helper function to my private library for just such an occasion:
(我很久以前就在这样的场合为我的私人图书馆添加了一个辅助函数:)
public static class EnumUtil {
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
}
}
Usage:
(用法:)
var values = EnumUtil.GetValues<Foos>();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…