DynamicMethod.InitLocals 属性

定义

获取或设置一个值,该值指示方法中的本地变量是否初始化为零。

public:
 property bool InitLocals { bool get(); void set(bool value); };
public bool InitLocals { get; set; }
member this.InitLocals : bool with get, set
Public Property InitLocals As Boolean

属性值

如果该方法中的本地变量初始化为零,则为 true;否则为 false。 默认值为 true

示例

下面的代码示例显示 InitLocals 动态方法的 属性。 此代码示例是为 DynamicMethod 类提供的一个更大示例的一部分。

// Display the default value for InitLocals.
if (hello->InitLocals)
{
    Console::Write("\r\nThis method contains verifiable code.");
}
else
{
    Console::Write("\r\nThis method contains unverifiable code.");
}
Console::WriteLine(" (InitLocals = {0})", hello->InitLocals);
// Display the default value for InitLocals.
if (hello.InitLocals)
{
    Console.Write("\r\nThis method contains verifiable code.");
}
else
{
    Console.Write("\r\nThis method contains unverifiable code.");
}
Console.WriteLine(" (InitLocals = {0})", hello.InitLocals);
' Display the default value for InitLocals.
If hello.InitLocals Then
    Console.Write(vbCrLf & "This method contains verifiable code.")
Else
    Console.Write(vbCrLf & "This method contains unverifiable code.")
End If
Console.WriteLine(" (InitLocals = {0})", hello.InitLocals)

注解

如果此属性设置为 true,则发出的 Microsoft 中间语言 (MSIL) 包括局部变量的初始化。 如果它设置为 false,则不会初始化局部变量,并且生成的代码无法验证。

适用于