473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system.enum.get values

I am observing some puzzling behavior with the GetValues method of enumerations. I
wonder if this something I just don't understand, or is this just wrong.

The documentation for the GetValues method says "The elements of the array [returned]
are sorted by the values of the enumeration constants". Further the docs state that
absent any underlying type definition of the enumeration, the type is assumed to be
int32 (a signed integer).

Consider the following code:

Public Enum MyEnum
Entry1
Entry2
Entry3
End Enum

Sub DisplayValues
For Each i As Integer In System.Enum.Get Values(GetType( MyEnum))
Debug.WriteLine (i.ToString)
Next
End Sub

As expected, the values displayed are 0, 1, and 2.

If I redefine the enumeration as:

Public Enum MyEnum
Entry1 = -1
Entry2 = 0
Entry3 = 1
End Enum

Then the values displayed are 0, 1, -1 (!)

It seems the values are sorted as *unsigned* integers.

Thus:

Public Enum MyEnum
Entry1 = -1
Entry2 = -2
Entry3 = 0
End Enum

displays 0, -2, -1 (!!)

What's going on here?

I've verified the same behavior occurs in both .NET 1.1 and 2.0.

-- Jeff
Oct 23 '06 #1
1 2364
In article <4s************ *************** *****@4ax.com>,
je******@comcas t.net says...
What's going on here?

I've verified the same behavior occurs in both .NET 1.1 and 2.0.
Yeah -- that does look odd and doesn't match the docs. But are you
relying on this behavior for something?

I guess I don't see it as a big deal (it's a bit of a performance hit
anyway since it uses reflection to get the values from the Enum).

--
Patrick Steele
http://weblogs.asp.net/psteele
Oct 26 '06 #2

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

Similar topics

1
2418
by: Daylor | last post by:
Public Enum COLORS RED= 0 GREEN=1 BLUD =2 ORANGE =4
6
6187
by: Marc Scheuner [MVP ADSI] | last post by:
Folks, I was trying to achieve the following thing: I have a "structure" that basically is a two-dimensional array of numeric values. Both dimensions are handled by enumeration types in C#: public enum Level = { low, medium, high }; public enum Foo = { bar, subbar, superbar }; Now my idea was to create a two-dimensional array using those enum's
2
61052
by: Mark | last post by:
Assume you've declared an enum .... public enum MyEnum { First, Second, Third } Without knowing the values of the enum, is it possible to iterate through all the possible values programmatically? Thanks in advance. Mark
2
6260
by: Armin Bajramovic | last post by:
Hi, I have enum: public enum StatusEnum { Active = 'A', Nonactive = 'N', Deleted = 'D' }
3
36303
by: cyshao | last post by:
Hi ,my friends: I have a enum type ,EMyEnum , defigned as . I just want to do something like this: foreach( EMyEnum crrEnum in EMyEnum ) { //do something }
1
5246
by: Powers | last post by:
I currently have a large number of enums implemented into my Web Service. I am reworking the XML serialization of these enums. At present, each enum has hardcoded values, for example: xAttrs = New XmlAttributes xEnum = New XmlEnumAttribute xEnum.Name = "0" xAttrs.XmlEnum = xEnum
34
11205
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
1
5473
by: moondaddy | last post by:
I need to use an ObjectDataProvider in a resource file to pull in the System.Window.TextAlignment enum which is part of the PresentationCore.DLL. I was able to do this with the HorizontalAlignment enum which uses the PresentationCore.DLL like this: xmlns:sysWin="clr-namespace:System.Windows;assembly=PresentationFramework" <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}"
3
3147
by: puzzlecracker | last post by:
What's the fastests way to find a number of values in enum. I came up with this. but I think it's over kill. enum Type { VAL1, VAL2, VAL3 }
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10443
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, 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...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
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...
0
6783
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();...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.