How to define a constant globally in C# (like DEBUG)

前端 未结 4 807
野性不改
野性不改 2020-12-18 20:13

I want to compile a project differently, according to a constant defined by #define, like this:

#define USE_COMPONENT_X

#if USE_COMPONENT_X
...

#endif
         


        
4条回答
  •  天命终不由人
    2020-12-18 21:04

    Hopefully I'm not way off topic, but rather than a "constant" perhaps define an interface for the constant's type and then use one of the many dependency injection frameworks to manage the definition, injection and lifetime of your "constant".

提交回复
热议问题