1 / 14

Enumeration

Enumeration. Definition. An enumeration is a set of related constants that define a value type where each constant is known as a member of the enumeration.

gizela
Download Presentation

Enumeration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Enumeration

  2. Definition • An enumeration is a set of related constants that define a value type where each constant is known as a member of the enumeration. • The enumerations provided by the .NET Framework are generally used to set object properties and to specify the values that are passed to methods.

  3. What is Enum • An Enum is a value type with a set of related named constants often referred to as an enumerator list. • The Enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined.

  4. Enum • Enums type can be Integer (Decimal, Short, Byte, Double etc.). • To use one of the integer data types, you can code an As clause that specifies the data type after the enumeration name. • Enum is used to create numeric constants in .NET framework. All member of Enum are of Enum type.

  5. Syntax of Enumeration Enum userdefinedname    member name 1[=value]    member name 2[=value]End Enum

  6. Example of Enumeration Enum DayOfWeek        Sun        Mon        Tue        Wed        Thu        Fri        Sat End Enum

  7. Enumeration • An enumeration defines a set of related constants. Each constant is known as a member of the enumeration. • To specify other values for the constants, you can code an equal sign after the constant name followed by the integer value.

  8. Example program of Enumeration Module Module1    Enum DayOfWeek        Sun        Mon        Tue        Wed        Thu        Fri        Sat    End Enum    Sub Main()

  9. Example Cont., Console.WriteLine("Day of week " & CInt(DayOfWeek.Sun) & " is " & DayOfWeek.Sun.ToString())        Console.WriteLine("Day of week " & CInt(DayOfWeek.Mon) & " is " & DayOfWeek.Mon.ToString())        Console.WriteLine("Day of week " & CInt(DayOfWeek.Tue) & " is " & DayOfWeek.Tue.ToString())        Console.WriteLine("Day of week " & CInt(DayOfWeek.Thu) & " is " & DayOfWeek.Wed.ToString())        Console.WriteLine("Day of week " & CInt(DayOfWeek.Fri) & " is " & DayOfWeek.Thu.ToString())        Console.WriteLine("Day of week " & CInt(DayOfWeek.Sat) & " is " & DayOfWeek.Fri.ToString())        Console.ReadLine()    End SubEnd Module

  10. Output

  11. Some points about Enum • Enums are enumerated data type in VB.NET. • Enums are not for end-user, they are meant for developers. • Enums are strongly typed constant. They are strongly typed, i.e. an Enum of one type may not be implicitly assigned to an Enum of another type even though the underlying value of their members are the same. • Enumerations (Enums) make your code much more readable and understandable.

  12. Cont., • Enum values are fixed. • Enum can be displayed as a string and processed as an Integer. • The default type is Integer, and the approved types are Byte, Sbyte, Short, UShort, UInteger, Long, and ULong.

  13. Cont., • Every Enum type automatically derives from System. • Enum and thus we can use System.Enum methods on Enums. • Enums are value types and are created on the stack and not on the heap. • The default and only access modifier supported is public.

  14. The End …… Thank You ……

More Related