C# enum to string auto-conversion?

Posted by dcompiled on Stack Overflow See other posts from Stack Overflow or by dcompiled
Published on 2010-06-09T23:11:44Z Indexed on 2010/06/09 23:22 UTC
Read the original article Hit count: 227

Is it possible to have the compiler automatically convert my Enum values to strings so I can avoid explicitly calling the ToString method every time. Here's an example of what I'd like to do:

enum Rank { A, B, C }

Rank myRank = Rank.A;
string myString = Rank.A; // Error: Cannot implicitly convert type 'Rank' to 'string'
string myString2 = Rank.A.ToString(); // OK: but is extra work

© Stack Overflow or respective owner

Related posts about c#

Related posts about enums