BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Attribute System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true) System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates the use of with a particular compiler that supports the use of this attribute. The property of the current attribute is initialized as "DEBUG".

`using System; using System.Diagnostics; public class MyClass { [ConditionalAttribute("DEBUG")] public static void Display() { Console.WriteLine("Compiled with DEBUG"); } } public class TestCondition { public static void Main() { Console.WriteLine("How was this compiled?"); MyClass.Display(); Console.WriteLine("<eop>"); } }`

When this code is compiled with the compilation-variable DEBUG defined at the callsite, the output when run is

How was this compiled?

Compiled with DEBUG

<eop>

When this code is compiled without the compilation-variable DEBUG defined at the callsite, the output when run is

How was this compiled?

<eop>

You can apply the attribute to methods and classes. However, its use on classes is valid only for types that are derived from . either will be ignored or will produce a compiler warning or error message if you apply it to any other type.

Applying to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with is defined. You will get a compilation error in Visual Studio if you apply this attribute to a method that does not return void. Applying to an attribute indicates that the attribute should not be emitted to metadata unless the conditional compilation symbol is defined. Any arguments passed to the method or attribute are still type-checked by the compiler.

You can use the following techniques to define conditional compilation symbols:

Use compiler command-line options; for example, /define:DEBUG.

Use environment variables in the operating system shell; for example, set DEBUG=1.

Use pragmas in the source code; for example, define the compilation variable as follows:

`#define DEBUG` `#Const DEBUG=True`

To undefine the variable, use the following:

`#Undef DEBUG` `#Const DEBUG=False`

Compilers that comply with the Common Language Specification (CLS) are permitted to ignore . The C#, Visual Basic, and C++ compilers support ; the JScript compiler does not support the attribute.

In Visual Basic, the AddressOf operator is not affected by this attribute. For example, Call CType(AddressOf delegate, Action) always invokes delegate, although Call delegate() might not.

is applied to the methods that are defined in the and classes.

For more information about how to use attributes, see Extending Metadata Using Attributes.

Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the current instance using .

  Initializes a new instance of the class.

  A string that specifies the case-sensitive conditional compilation symbol that is associated with the attribute.
  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A that contains the pre-processing identifier that makes callable the target method of the current instance.

  This property is read-only.

  Gets the conditional compilation symbol that is associated with the attribute.

  0
0