System.Dynamic.DynamicObject.TrySetIndex Method

Provides the implementation for operations that set a value by index. Classes derived from the System.Dynamic.DynamicObject class can override this method to specify dynamic behavior for operations that access objects by a specified index.

Syntax

public virtual bool TrySetIndex (SetIndexBinder binder, object[] indexes, object value)

Parameters

binder
Provides information about the operation.
indexes
The indexes that are used in the operation. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the System.Dynamic.DynamicObject class, indexes[0] is equal to 3.
value
The value to set to the object that has the specified index. For example, for the sampleObject[3] = 10 operation in C# (sampleObject(3) = 10 in Visual Basic), where sampleObject is derived from the System.Dynamic.DynamicObject class, value is equal to 10.

Returns

true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.

Remarks

Classes derived from the System.Dynamic.DynamicObject class can override this method to specify how operations that access an object by index should be performed for a dynamic object. When the method is not overridden, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)

If this method is overridden, it is automatically invoked when you have an operation like sampleObject[3] = 10 in C# or sampleObject(3) = 10 in Visual Basic, where sampleObject is derived from the System.Dynamic.DynamicObject class.

Requirements

Namespace: System.Dynamic
Assembly: System.Core (in System.Core.dll)
Assembly Versions: 4.0.0.0