0

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

1
  • why do you never accept answers? It can be useful for others in the future and it gives points to you and he who helped you Commented Jan 2, 2014 at 0:44

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.