What is the usage of #if DEBUG
pre-processor directive in C#? When must we use this?
You might feel more comfortable with the Conditional
attribute, which can be used to exclude entire methods, without needing to complicate the source with conditionals on the calling side:
[Conditional("DEBUG")]
void Foo()
{
}
Foo()
can be safely called in both debug and release - however in release mode, it would be a no-op.