473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the number of items in a enum

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

TIA - Jeff.
Feb 1 '06 #1
4 2310
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

Look at Enum.GetValues and Enum.GetNames.


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
mailto:la***@vk arlsen.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

TIA - Jeff.

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

foreach(string s in Enum.GetNames(t ypeof(Colors)))
Console.WriteLi ne(s);

There is also a GetValues(..)

Hans Kesting
Feb 1 '06 #4

"UJ" <fr**@nowhere.c om> wrote in message
news:O3******** ******@TK2MSFTN GP14.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

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 (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
by: lglmi | last post by:
'********************START OF BAS MODULE******************** Option Explicit Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long
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 enum DirectionEnum {Up, Down, Left, Right}; If I needed to get an enum reference based on the dropdown selection, as of today I would do the following: DirectionEnum myEnum; // Declare enum. If(someCombobox.Text == "Up") myEnum ==...
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 prefix. For example: My C# code has this... public enum SIZE_OPTIONS { szZoom = -1, szFitWindow,
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 ?
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
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 combobox, but I can't find anything that will let me do that. - Don
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 reflect that the 3 items have been deleted only to discover that the 3 items appear, however when I click on them to display their information which runs a datareader over the same database it appears that the data has now gone. I wondered whether...
by: tony | last post by:
Hello!! Is it possible to get the number of items in an enum. //Tony
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.