|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
system.enum.getvalueswonder 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.GetValues(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 -- Jeff Jeff Mason <je.ma***@comcast.net> wrote:
> I am observing some puzzling behavior with the GetValues method of enumerations. I I think it's just plain wrong, unfortunately. I suggest you use > 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). http://connect.microsoft.com/VisualStudio to report it as a documentation bug. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message Sadly it seems that documentation bugs placed there get resolved as news:MPG.1fa74162e291569b98d579@msnews.microsoft.com... > Jeff Mason <je.ma***@comcast.net> wrote: >> 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). > > I think it's just plain wrong, unfortunately. I suggest you use > http://connect.microsoft.com/VisualStudio to report it as a > documentation bug. "external" and nothing is done. Show quote > > -- > Jon Skeet - <sk***@pobox.com> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet > If replying to the group, please do not mail me too Ben Voigt <rbv@nospam.nospam> wrote:
> > I think it's just plain wrong, unfortunately. I suggest you use Hmm... that's not been my experience, I have to say. The alternative is > > http://connect.microsoft.com/VisualStudio to report it as a > > documentation bug. > > Sadly it seems that documentation bugs placed there get resolved as > "external" and nothing is done. to click on the link in the MSDN page at fault. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=156103news:MPG.1fa746ce8832a1dd98d57b@msnews.microsoft.com... > Ben Voigt <rbv@nospam.nospam> wrote: >> > I think it's just plain wrong, unfortunately. I suggest you use >> > http://connect.microsoft.com/VisualStudio to report it as a >> > documentation bug. >> >> Sadly it seems that documentation bugs placed there get resolved as >> "external" and nothing is done. > > Hmm... that's not been my experience, I have to say. The alternative is > to click on the link in the MSDN page at fault. > The MSDN page has a rating of "1", the worst possible, as well. Microsoft just wants to sell their "Certified Developer" courses and bad public documentation helps them do that. Show quote > -- > Jon Skeet - <sk***@pobox.com> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet > If replying to the group, please do not mail me too Jeff Mason wrote:
I reported this bug to Microsoft back in May or June. They acknowledged the problem -- that the array is sorted as unsigned integers. They also said that the behavior will not change as it may break existing code. I asked them to update the documentation -- but I haven't heard back from them. -- Show quote// Lee Silver // Information Concepts Inc. > 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.GetValues(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 > > > > -- Jeff |
|||||||||||||||||||||||