VB.Net - Syntax


Enum enShapes 'As integer - by default  
   Triangle ' This is assumed to be zero
   Square '1
   Rectangle '2
   Circle ' 3
   Unknown = -999
End Enum

Dim Shape As enShapes = enShapes.Triangle

System.Windows.Forms.MessageBox.Show([System.Enum].GetName(GetType(EN_SHAPES,2); // = Green

Even though Enum values are internally stored as integers, by default you are not allowed to assign a number to an Enum variable if Option Strict is on.
You must convert the number to the proper Enum type before assigning it an Enum variable.

Shape = CType(1, enShapes) 


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext