I have the following enum:
public enum EReferenceKey {
Accounts = 1,
Emails = 3,
Phones = 4
}
When my enum variable pk is Accounts and I try to convert this to “01” using
var a = pk.ToString("00");
it gives me the following exception:
Format String can be only “G”, “g”, “X”, “x”, “F”, “f”, “D” or “d”
Can someone explain what I am doing wrong?
You need to cast it to int before attempting that format string. Enum has its own ToString implementation, as such your int format string is not correct.