Saturday, October 27, 2007

Enumerations of VB.NET & C#

Enumerations

In vb.net & c# language Enumerations are differ. Code of Enumerations of vb.net & c# language.
_____________________________________________________________


VB.NET

Enum Action
Start
[Stop] ' Stop is a reserved word
Rewind
Forward
End Enum

Enum Status
Flunk = 50
Pass = 70
Excel = 90
End Enum

Dim a As Action = Action.Stop
If a <> Action.Start Then _
Console.WriteLine(a.ToString & " is " & a) ' Prints "Stop is 1"

Console.WriteLine(Status.Pass) ' Prints 70
Console.WriteLine(Status.Pass.ToString()) ' Prints Pass

------------------------------------------------------------------------------------------------

C#


enum Action {Start, Stop, Rewind, Forward};
enum Status {Flunk = 50, Pass = 70, Excel = 90};

Action a = Action.Stop;
if (a != Action.Start)
Console.WriteLine(a + " is " + (int) a); // Prints "Stop is 1"

Console.WriteLine((int) Status.Pass); // Prints 70
Console.WriteLine(Status.Pass); // Prints Pass

-------------------------------------------------------------------------------------------------

Note: This code applicable for both desktop and web application.

-------------------------------------------------------------------------------------------------

No comments: