Determine the name of a constant based on the value

后端 未结 7 947
广开言路
广开言路 2021-01-05 22:07

Is there a way of determining the name of a constant from a given value?

For example, given the following:

public const uint ERR_OK = 0x00000000;

Ho

7条回答
  •  不知归路
    2021-01-05 22:30

    You won't be able to do this since constants are replaced at compilation time with their literal values.

    In other words the compiler takes this:

    class Foo
    {
        uint someField = ERR_OK;
    }
    

    and turns it into this:

    class Foo
    {
        uint someField = 0;
    }
    

提交回复
热议问题