0

Is it possible to create what I can best describe as a system defined object in VB.Net on VS2010? I have included as picture from the color class describing the functionality I was wondering about.

enter image description here

Also, if there is a better name for this please let me know so I can rename the question.

1
  • 1
    That looks like an Enum. Commented Mar 15, 2013 at 0:36

2 Answers 2

1
Enum Color
    Red
    Orange
    Yellow
    Green
    Blue
    Purple
End Enum
Sign up to request clarification or add additional context in comments.

Comments

1

An Enum is more or less a type declaration with members that are aliases to numeric values.

In the example from your question, the Color type is a Structure (a value type), and the different options you see for available colors are actually Shared Properties defined in the Structure. The reason it is done this way and not as an Enum is because the Color type is not a numeric type.

For example, if you wanted to make a Color class of your own, it would look like:

Public Structure MyColor
    Property Red as Byte
    Property Green as Byte
    Property Blue as Byte

    Sub New(r as Byte, g as Byte, b as Byte)
        Red = r
        Green = g
        Blue = b
    End Sub

    Shared ReadOnly Property BrightRed as MyColor
        Get
            Return New Color(255,0,0)
        End Get
    End Property
End Structure

In the above example, BrightRed would show up as an option when you type "MyColor." in the code editor.

1 Comment

This make a lot of sense, I will play around with this some.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.