Near Shore Consulting Ltd.
View Yves Rochon's profile on LinkedIn
Our Blog
Our Blog
Enum tips
Location: BlogsNear Shore Blog    
Posted by: admin 7/9/2007 6:49 AM

Occationally, when using enums, it is useful to evaluate a member's name at run-time. The ToString() method makes this task really easy, just look at the code snippet below:

public enum MyEnum

{

alfa = 1,

beta = 2,

gamma = 3

}

 

private void cmdGo_Click(object sender, EventArgs e)

{

MyEnum myEnumVar;

myEnumVar = MyEnum.gamma;

string myMember;

myMember = myEnumVar.ToString();

// myMember is not equal to "gamma"

}

Permalink |  Trackback
Blog
Near Shore Consulting  |  Terms Of Use  |  Privacy Statement