How does C# compiler remove Debug.Assert's in release builds?

前端 未结 3 510
栀梦
栀梦 2021-02-04 00:13

I was recently going through some code and considering whether I need to be careful with the expressions placed inside Debug.Assert statements, such as expensive op

3条回答
  •  借酒劲吻你
    2021-02-04 00:46

    The methods on the debugger use the pseudo-custom attribute, ConditionalAttribute, which the compiler detects and removes any calls to any methods with that attribute unless the specified compilation symbol (in this case, DEBUG) is defined. Anyone may use the attribute on void methods without any out parameters.

提交回复
热议问题