The Conditional Attribute

You want to exclude a method and any statements that call it from a particular version of your application. How should you do it?

Prefer the Conditional attribute instead of the #if directive to exclude methods and all the statements that call them.

The Conditional attribute can abandon all statements that call a method, but it won’t discard the method definition itself. However, you can invoke the method via reflection.


// This is incorrect.

void ShowSplashScreen() {

// This is correct. No need for an #if directive.

void ShowSplashScreen() {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s