Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 20437 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > Enum Conversion Operations in C# ...
Akshayblevel

Enum Conversion Operations in C#

 Blog author: Akshayblevel | Posted on: 8/6/2012 | Category: C# Blogs | Views: 886 | Status: [Member] | Points: 75 | Alert Moderator   
Ads

public enum EmloyeeRole
{
  None = 0,
  Manager = 1,
  Admin = 2,
  Operator = 3
}

enum to int - To convert a enum to interger simply type cast the enum into integer

EmloyeeRole role = EmloyeeRole.Manager; 
int roleInterger = (int)role;
int to enum

int to enum

int roleInterger = 2; 
EmloyeeRole role = (EmloyeeRole)roleInterger;

string to enum - If you have string value and you want to type cast that into enum

string roleString = "Operator"; 
EmloyeeRole role = (EmloyeeRole)Enum.Parse(typeof(EmloyeeRole), roleString);

enum to string

EmloyeeRole role = EmloyeeRole.Manager; 
string roleString = role.ToString();


Found interesting? Add this to:



 More Blogs from Akshayblevel

 More ...

About akshay patel

Experience:5 year(s)
Home page:http://www.dotnetfunda.com
Member since:Friday, March 12, 2010
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 9:44:42 PM