SetValue Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Sets the property value of a specified object with optional index values for index properties.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual void SetValue(
	Object obj,
	Object value,
	Object[] index
)

Parameters

obj
Type: System..::..Object
The object whose property value will be set.
value
Type: System..::..Object
The new property value.
index
Type: array<System..::..Object>[]()[][]
Optional index values for indexed properties. This value should be nullNothingnullptrunita null reference (Nothing in Visual Basic) for non-indexed properties.

If this PropertyInfo object is a value type and value is nullNothingnullptrunita null reference (Nothing in Visual Basic), then the property will be set to the default value for that type.

To determine whether a property is indexed, use the GetIndexParameters method. If the resulting array has 0 (zero) elements, the property is not indexed.

This is a convenience method that calls the runtime implementation of the abstract SetValue(Object, Object, BindingFlags, Binder, array<Object>[]()[][], CultureInfo) method, specifying BindingFlags..::..Default for the BindingFlags parameter, nullNothingnullptrunita null reference (Nothing in Visual Basic) for Binder, and nullNothingnullptrunita null reference (Nothing in Visual Basic) for CultureInfo.

To use the SetValue method, first get a Type object that represents the class. From the Type, get the PropertyInfo. From the PropertyInfo, use the SetValue method.

Show: