What's difference between Enum and type in VB.NET?
Printable View
What's difference between Enum and type in VB.NET?
An Enum is meant for if you have unchanging values that are related to each other. Enum's can also only return the following data types: Byte, Integer, Long, SByte, Short, UInteger, ULong, or UShort.
A Type can be thought of the foundation of a programming language. It's the most basic form of a given value.
Oh my God !!!
Where is the Type command in VB.Net ?!!!
Type was a useful command to make user-defined variables in modules and classes...
an example about Type:
Is the Enum equivalent of Type in VB.Net ?!Code:
'''''''' In Module1 in a Visual Basic 6 Project '''''''''''
Public Type test1
a1 As String
a2 As Byte
a3 As String * 3
a4 As Integer
End Type
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''' In Form1 in a Visual Basic 6 Project '''''''''''
Private Sub Form_Load()
Dim a_final As test1
a_final.a1 = "test"
a_final.a2 = 2
a_final.a3 = "ali"
a_final.a4 = 6536
MsgBox a_final.a1
MsgBox a_final.a2
MsgBox a_final.a3
MsgBox a_final.a4
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
That looks like a class:
Code:Public Class Test1
Public a1 As String
Public a2 As Byte
Public a3 As String '* 3? Don't know what that is...
Public a4 As Integer
End Class
Private Sub form_load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.OnLoad()
Dim a_final As Test1 = New Test1 With {.a1 = "test", .a2 = 2, .a3 = "ali", .a4 = 6536}
End Sub
There are 5 kinds of 'types' in VB:
Class
Structure (this is closer to the 'Type' of VB6)
Interface
Enum
Delegate
If the values are going to be changing, use a CLASS. If they values are static use a STRUCTURE.
Also, regardless of whether you declare a class or structure, don't put anything in a module. Classes, structures and modules are all first-class types so each one would best be declared in its own code file. None of them belong in any of the others except under specific circumstances.