473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting the number of items in a enum

UJ
Is there a way to get the number of items that are in an enum? I'm trying to
find out how many items there are so that I can hit every one of them to
test.

TIA - Jeff.
Feb 1 '06 #1
4 2280
UJ wrote:
Is there a way to get the number of items that are in an enum? I'm trying to
find out how many items there are so that I can hit every one of them to
test.


Look at Enum.GetValues and Enum.GetNames.

Jon

Feb 1 '06 #2
> Is there a way to get the number of items that are in an enum? I'm
trying to find out how many items there are so that I can hit every
one of them to test.

TIA - Jeff.


Look at Enum.GetValues/GetNames

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Feb 1 '06 #3
> Is there a way to get the number of items that are in an enum? I'm trying to
find out how many items there are so that I can hit every one of them to
test.

TIA - Jeff.


enum Colors { Red, Green, Blue, Yellow };

foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);

There is also a GetValues(..)

Hans Kesting
Feb 1 '06 #4

"UJ" <fr**@nowhere.com> wrote in message
news:O3**************@TK2MSFTNGP14.phx.gbl...
Is there a way to get the number of items that are in an enum? I'm trying
to find out how many items there are so that I can hit every one of them
to test.

TIA - Jeff.


Enum.GetNames/GetValues is necessary as everyone hs said but might not be
sufficient because:

1) Duplicate values are allowed. This isn't really a problem but you might
want to weed out duplicate values.

2) The enum might have the FlagsAttribute in which case you need to OR
together all possible combinations.

Feb 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number...
0
by: lglmi | last post by:
'********************START OF BAS MODULE******************** Option Explicit Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long...
2
by: Rene | last post by:
Say that I create a combobox with pull down items that map directly to an enum. For example the dropdown items could be "Up", "Down", "Left" and "Right" and the enum could be declare as: public...
1
by: MLM450 | last post by:
I am converting a C++ control to C#. When a C++ host app is compiled with the tlb file of my new control, it changes my public enums. Each item in the enumerator list has the enum name added as a...
12
by: Mike Smith | last post by:
Hey anyone knows how to find an item in a list view based on text ? Cant seem to get the IndexOf method working. would the LVM_FINDITEM method using SendMessage API work in .Net ?
2
by: Don | last post by:
Is is possible to find a count of the number of items in an enumeration? Something like: Public Enum MyEnum First = 1 Second = 2 Third = 3 End Enum
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
3
by: tony | last post by:
Hello!! Is it possible to get the number of items in an enum. //Tony
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.