ConditionalAttribute(String) 构造函数

定义

初始化 ConditionalAttribute 类的新实例。

public:
 ConditionalAttribute(System::String ^ conditionString);
public ConditionalAttribute (string conditionString);
new System.Diagnostics.ConditionalAttribute : string -> System.Diagnostics.ConditionalAttribute
Public Sub New (conditionString As String)

参数

conditionString
String

一个字符串,它指定与此属性关联的区分大小写的条件编译符号。

示例

以下示例演示如何使用 ConditionalAttribute 构造函数。 此示例是为 类提供的更大示例的一 ConditionalAttribute 部分。

[Conditional("CONDITION1")]
public static void Method1(int x)
{
    Console.WriteLine("CONDITION1 is defined");
}

[Conditional("CONDITION1"), Conditional("CONDITION2")]
public static void Method2()
{
    Console.WriteLine("CONDITION1 or CONDITION2 is defined");
}
<ConditionalAttribute("CONDITION1")> _
Shared Sub Method1(x As Integer)
    Console.WriteLine("CONDITION1 is defined")
End Sub

<ConditionalAttribute("CONDITION1"), ConditionalAttribute("CONDITION2")> _
Shared Sub Method2()
    Console.WriteLine("CONDITION1 or CONDITIOIN2 is defined")
End Sub

适用于