Поделиться через


Collection.Add Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Adds an element to a Collection object.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

Syntax

'Declaration
Public Sub Add ( _
    Item As Object, _
    Key As String, _
    Before As Object, _
    After As Object _
)
public void Add(
    Object Item,
    string Key,
    Object Before,
    Object After
)

Parameters

  • Item
    Type: System.Object
    Required. An object of any type that specifies the element to add to the collection.
  • Key
    Type: System.String
    Optional. A unique String expression that specifies a key string that can be used instead of a positional index to access this new element in the collection.
  • Before
    Type: System.Object
    Optional. An expression that specifies a relative position in the collection. The element to be added is placed in the collection before the element identified by the Before argument. If Before is a numeric expression, it must be a number from 1 through the value of the collection's Count property. If Before is a String expression, it must correspond to the key string specified when the element being referred to was added to the collection. You cannot specify both Before and After.
  • After
    Type: System.Object
    Optional. An expression that specifies a relative position in the collection. The element to be added is placed in the collection after the element identified by the After argument. If After is a numeric expression, it must be a number from 1 through the value of the collection's Count property. If After is a String expression, it must correspond to the key string specified when the element referred to was added to the collection. You cannot specify both Before and After.

Remarks

The Before or After argument must refer to an existing element of the collection; otherwise, an error occurs.

An error also occurs if a specified Key value matches the key for an existing element of the collection.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.