Live Chat Icon For mobile
Live Chat Icon

How do I conditionally include certain methods based on some preprocessor defines?

Platform: WinForms| Category: Debugging

You have the regular #if and #else preprocessor directive inside which you could place your code. Take a look at the ‘C# Preprocessor Directives’ section for the complete list of preprocessor directives.

There is also a concept of ‘Conditonal Methods’ that will let you declare some methods as conditional methods based on the presence of certain preprocessor directives, using the ConditionalAttribute. Then the compiler will not only ignore the method, but also the method-call if the preprocessor symbol is not defined. Take a look at this MSDN section for more information:

Conditional Methods Tutorial

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.