I want to convert enum
to string
with three digits in C#.
Like this:
enum test : short
{
asdf, qwer, zxcv
}
test t = test.qwer;
string result = t.ToString("%03D") // Is this right?
I want to print 001
In a normal enumeration you can just cast as an integer, then call "ToString" with a format specified. In your case that should look like:
test t = test.qwer;
string result = ((int)t).ToString("000");
That should do it! Good luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.