how to get items count <b>OF</b> an Enumaration?
-
It is clear. Imagine an enumaration Enum Crypt ASD = 1 SDE = 3 DFR = 6 RTE = 9 TEL = 12 MGJ = 17 EIV = 23 ... . End Enum I need items count of Enum :) for example any property like Crypt.Count if there is no way i will write my own class.
It's easy - use Enum class
public enum MyType { First, Second, Third, Fourth };
Then you can retrive number of items in this way:int numOfEnumItems = Enum.GetValues(typeof(MyType)).Length
DevIntelligence.com - My blog for .Net Developers -- modified at 8:26 Tuesday 17th January, 2006 -
It is clear. Imagine an enumaration Enum Crypt ASD = 1 SDE = 3 DFR = 6 RTE = 9 TEL = 12 MGJ = 17 EIV = 23 ... . End Enum I need items count of Enum :) for example any property like Crypt.Count if there is no way i will write my own class.
It wasn't clear at all, i assume you are after the number of options in a specified enumeration??
string[] enumCount = System.Enum.GetNames(typeof(myEnum));
MessageBox.Show(enumCount.Length.ToString());That should give you what i think you're after. Cheers Kev
-
It's easy - use Enum class
public enum MyType { First, Second, Third, Fourth };
Then you can retrive number of items in this way:int numOfEnumItems = Enum.GetValues(typeof(MyType)).Length
DevIntelligence.com - My blog for .Net Developers -- modified at 8:26 Tuesday 17th January, 2006 -
It is clear. Imagine an enumaration Enum Crypt ASD = 1 SDE = 3 DFR = 6 RTE = 9 TEL = 12 MGJ = 17 EIV = 23 ... . End Enum I need items count of Enum :) for example any property like Crypt.Count if there is no way i will write my own class.