C-Sharp enum type

Hello friends, in this article you will learn about c# enum type.

enum type is unique value type with a set of named constants.

if you have a variable with unique distinct set of value like color, you can define it by using enum type as follows.

using System; enum Color { Red, Green, Blue }

Moreover, you can also assign numeric values with type.

using System; enum Color:int { Red=0, Green=1, Blue=2 }

you can access enum value by

int i = (int)Color.Blue; // int i = 2;

you can access enum named variable by cast enum.

Color c = (Color)2;

If you have any query or question or topic on which, we might have to write an article for your interest or any kind of suggestion regarding this post, Just feel free to write us, by hit add comment button below or contact via Contact Us form.


Your feedback and suggestions will be highly appreciated. Also try to leave comments from your valid verified email account, so that we can respond you quickly.

 
 

{{c.Content}}

Comment By: {{c.Author}}  On:   {{c.CreatedDate|date:'dd/MM/yyyy'}} / Reply


Categories