NameValueCollection.Item[] 属性

定义

获取或设置指定的项 NameValueCollection

重载

名称 说明
Item[Int32]

获取指定索引处的 NameValueCollection项。

Item[String]

获取或设置具有指定键的 NameValueCollection项。

Item[Int32]

Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs

获取指定索引处的 NameValueCollection项。

public:
 property System::String ^ default[int] { System::String ^ get(int index); };
public string this[int index] { get; }
public string? this[int index] { get; }
member this.Item(int) : string
Default Public ReadOnly Property Item(index As Integer) As String

参数

index
Int32

在集合中查找的项的从零开始的索引。

属性值

String包含集合的指定索引处的值的逗号分隔列表。

例外

index 超出集合的有效索引范围。

注解

此属性提供使用以下语法访问集合中的特定元素的功能: myCollection[index]

无法设置此属性。 若要在指定的索引处设置值,请使用 Item[GetKey(index)]

C# 语言 使用此关键字来 定义索引器,而不是实现 Item[] 属性。 Visual Basic实现 Item[] 作为 default 属性,它提供相同的索引功能。

检索指定索引处的值是一个 O(n) 操作,其中 n 是值数。

另请参阅

适用于

Item[String]

Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs

获取或设置具有指定键的 NameValueCollection项。

public:
 property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); void set(System::String ^ name, System::String ^ value); };
public string this[string name] { get; set; }
public string? this[string? name] { get; set; }
member this.Item(string) : string with get, set
Default Public Property Item(name As String) As String

参数

name
String

String要查找的项的键。 键可以是 null

属性值

包含 String 与指定键关联的值的逗号分隔列表(如果找到);否则为 null

例外

集合是只读的,并且操作尝试修改集合。

注解

此属性提供使用以下语法访问集合中的特定元素的功能: myCollection[name]

如果集合中已存在指定的键,则设置此属性将覆盖具有指定值的现有值列表。 若要将新值追加到现有值列表中,请使用 Add 该方法。

如果集合中不存在指定的键,则设置此属性会使用指定的键和指定的值创建一个新条目。

Caution

如果找不到指定的键,则此属性在以下情况下返回 null :1)如果找到指定的键并且其关联的值为 null,则为 2)。 此属性不区分这两种情况。

C# 语言 使用此关键字来 定义索引器,而不是实现 Item[] 属性。 Visual Basic实现 Item[] 作为 default 属性,它提供相同的索引功能。

检索或设置与指定键关联的值是 O(n) 操作,其中 n 值数。

另请参阅

适用于