daniel
daniel

Reputation: 35703

convert uint to const name

I have some constant error codes in a class:

 public class EDSDK
 {
    public const uint EDS_ERR_UNIMPLEMENTED = 0x00000001;  
    public const uint EDS_ERR_INTERNAL_ERROR = 0x00000002;
    public const uint EDS_ERR_MEM_ALLOC_FAILED = 0x00000003;

}

How can I get the const name from an (hex encoded) value?

Upvotes: 0

Views: 273

Answers (1)

Ken Hung
Ken Hung

Reputation: 190

If you use enum, it can be done with Enum.ToString():

public enum EDSDK
{
    EDS_ERR_UNIMPLEMENTED = 0x00000001,
    EDS_ERR_INTERNAL_ERROR = 0x00000002,
    EDS_ERR_MEM_ALLOC_FAILED = 0x00000003
}



EDSDK status = (EDSDK)0x00000001;
string statusString = status.ToString();

Upvotes: 2

Related Questions