This documentation is archived and is not being maintained.

PropertyInfo.SetValue Method (Object, Object, Object[])

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Overridable Sub SetValue( _
   ByVal obj As Object, _
   ByVal value As Object, _
   ByVal index() As Object _
public virtual void SetValue(
 object obj,
 object value,
 object[] index
public: virtual void SetValue(
 Object* obj,
 Object* value,
 Object* index __gc[]
public function SetValue(
   obj : Object,
 value : Object,
 index : Object[]


The object whose property value will be set.
The new value for this property.
Optional index values for indexed properties. This value should be a null reference (Nothing in Visual Basic) for non-indexed properties.


Exception Type Condition
ArgumentException The index array does not contain the type of arguments needed.


The property's Get method is not found.

TargetException The object does not match the target type, or a property is an instance property but obj is a null reference (Nothing in Visual Basic).
TargetParameterCountException The number of parameters in index does not match the number of parameters the indexed property takes.
MethodAccessException There was an illegal attempt to access a private or protected method inside a class.


This is a convenience method that provides an implementation for the abstract SetValue method with a BindingFlags parameter of DefaultChangeType, the Binder set to a null reference (Nothing in Visual Basic), and the CultureInfo set to a null reference (Nothing).

To use the SetValue method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the SetValue method.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

.NET Framework Security: 

See Also

PropertyInfo Class | PropertyInfo Members | System.Reflection Namespace | PropertyInfo.SetValue Overload List