473,405 Members | 2,444 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,405 software developers and data experts.

Strange Enum Properties

When I make an enumeration, the various values are accessed by
<enum_name>.<option1>. I noticed that each option has properties that
return any of the options in the enumeration, as can easily seen by
listing the members (typing a . after the expression). This way, you
can make expressions like:
<enum_name>.<option1>.<option2>.<option3>.<option1 > e.t.c. The
expression takes on the value of the last option.

I was wondering what purpose these properties have. Does anybody know
this?

Below is an example made on an empty VB.NET Windows application. It
compiles and runs (doing very little of course).

'----------------------------
Option Strict On
Option Explicit On
Public Class Form1
Inherits System.Windows.Forms.Form

'(#Region " Windows Form Designer generated code ")

Private Enum MyEnum
FirstOption
SecondOption
ThirdOption
End Enum
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim test As MyEnum = MyEnum.FirstOption
Select Case test

Case
MyEnum.FirstOption.SecondOption.ThirdOption.ThirdO ption.ThirdOption.FirstOption

Case MyEnum.SecondOption

Case MyEnum.ThirdOption

End Select

End Sub
End Class

Nov 21 '05 #1
2 1356
Internally, an enum is written as struct

foe g
Enum Color
{
Red
Green
Blue
}

will be considered as

Struct Color
{
public int value;

public const Color Red = 0;
public const Color Blue = 1;
public const Color Green = 2;
}

Hence, you can write Color.Red.Blue.Green which will turn out to be
Color.Red.Blue.Green.value (i.e. 2)

Does this help ?
Kalpesh

Nov 21 '05 #2
Actually, it's a little different.
With that structure definition, you couldn't have:
Dim test As Color = Color.Red Then ...

You'd need:
Dim test As Color
test.value = Color.Red

So, an enum is similar to a struct but allows access to the 'value' property
by default.

Also, the fact that you can access the various values from each other is
just due to a feature (or quirk)
in VB which allows you to access shared items from instance members.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
"Kalpesh" wrote:
Internally, an enum is written as struct

foe g
Enum Color
{
Red
Green
Blue
}

will be considered as

Struct Color
{
public int value;

public const Color Red = 0;
public const Color Blue = 1;
public const Color Green = 2;
}

Hence, you can write Color.Red.Blue.Green which will turn out to be
Color.Red.Blue.Green.value (i.e. 2)

Does this help ?
Kalpesh

Nov 21 '05 #3

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

Similar topics

9
by: thechaosengine | last post by:
Hi all, I have a problem that I havent really come accross before. I need to be able to allow the user to set a dropdown control to a particular colour value. The permissable values come from...
7
by: cppaddict | last post by:
Hi, I've been trying to debug a strange runtime error for the last 5 hours... I'm hoping someone might have an insight about it. I have an application that creates a vector of MyDisplay...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
3
by: Arnold Schrijver | last post by:
I wrote a program that draws items to the screen and maintains a set of Offset values. There was a bug in the code, because objects were positioned wrongly. While debugging I found some peculiar...
10
by: Michael Feld | last post by:
Hello, does anyone know how to produce a data type which offers Enum-like IntelliSense in VS 2005? What I am trying to create is a type which is very similar to an enum, i.e. has a fixed set of...
4
by: veerleverbr | last post by:
Suppose having define an enum like this: public enum SomeEnum { Something, SomethingElse }
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
34
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...
4
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
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...
0
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,...

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.