System.Reflection.Emit.FieldBuilder.SetConstant Method

Sets the default value of this field.

Syntax

public void SetConstant (object defaultValue)

Parameters

defaultValue
The new default value for this field.

Remarks

defaultValue is restricted to the following types: Boolean, SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, UInt64, Single, Double, DateTime, Char, String, and Enum. If the field type is a reference type, CLS compliance requires defaultValue to be null. However, starting with the net_v40_long, defaultValue can be non-null for a reference type as long as the value can be assigned to that reference type. For example, an Int32 value can be assigned to a field of type object. This is not CLS-compliant, but it can be useful in interop scenarios.

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0