System.Net.WebHeaderCollection Class

Assembly: System.dll
Namespace: System.Net
Summary
Contains protocol headers associated with a request or response.
C# Syntax:
[Serializable]
public class WebHeaderCollection : NameValueCollection
Remarks
The WebHeaderCollection class is generally accessed through WebRequest.Headers or WebResponse.Headers. Some common headers are considered restricted and are either exposed directly by the API (such as Content-Type) or protected by the system and cannot be changed.

The restricted headers are:

See also:
System.Net Namespace

System.Net.WebHeaderCollection Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the WebHeaderCollection class.
Public Properties
AllKeys
(inherited from System.Collections.Specialized.NameValueCollection)
Read-only

See base class member description: System.Collections.Specialized.NameValueCollection.AllKeys


Gets all the keys in the NameValueCollection.
Count
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Read-only

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Count


Gets the number of key-and-value pairs contained in the NameObjectCollectionBase instance.
Item
(inherited from System.Collections.Specialized.NameValueCollection)
Read-only

Overloaded:
Item[int index] {get

See base class member description: System.Collections.Specialized.NameValueCollection.Item


Gets the entry at the specified index of the NameValueCollection.
Item
(inherited from System.Collections.Specialized.NameValueCollection)
Read-write

Overloaded:
Item[string name] {get

See base class member description: System.Collections.Specialized.NameValueCollection.Item


Gets or sets the entry with the specified key in the NameValueCollection.
Keys
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Read-only

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Keys


Gets a NameObjectCollectionBase.KeysCollection instance that contains all the keys in the NameObjectCollectionBase instance.
Public Methods
Add
(inherited from System.Collections.Specialized.NameValueCollection)
Overloaded:
Add(NameValueCollection c)

See base class member description: System.Collections.Specialized.NameValueCollection.Add


Copies the entries in the specified NameValueCollection to the current NameValueCollection.
Add Overloaded:
Add(string header)

Inserts the specified header into the collection.
Add Overloaded:
Add(string name, string value)

Overridden:
Inserts a new header with the specified name and value into the collection.
Clear
(inherited from System.Collections.Specialized.NameValueCollection)
See base class member description: System.Collections.Specialized.NameValueCollection.Clear


Invalidates the cached arrays and removes all entries from the NameValueCollection.
CopyTo
(inherited from System.Collections.Specialized.NameValueCollection)
See base class member description: System.Collections.Specialized.NameValueCollection.CopyTo


Copies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
Get
(inherited from System.Collections.Specialized.NameValueCollection)
Overloaded:
Get(int index)

See base class member description: System.Collections.Specialized.NameValueCollection.Get


Gets the values at the specified index of the NameValueCollection combined into one comma-separated list.
Get
(inherited from System.Collections.Specialized.NameValueCollection)
Overloaded:
Get(string name)

See base class member description: System.Collections.Specialized.NameValueCollection.Get


Gets the values associated with the specified key from the NameValueCollection combined into one comma-separated list.
GetEnumerator
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetEnumerator


Returns an enumerator that can iterate through the NameObjectCollectionBase.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetKey
(inherited from System.Collections.Specialized.NameValueCollection)
See base class member description: System.Collections.Specialized.NameValueCollection.GetKey


Gets the key at the specified index of the NameValueCollection.
GetObjectData
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetObjectData


Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetValues
(inherited from System.Collections.Specialized.NameValueCollection)
Overloaded:
GetValues(int index)

See base class member description: System.Collections.Specialized.NameValueCollection.GetValues


Gets the values at the specified index of the NameValueCollection.
GetValues Overloaded:
GetValues(string header)

Overridden:
Gets an array of header values stored in a header.
HasKeys
(inherited from System.Collections.Specialized.NameValueCollection)
See base class member description: System.Collections.Specialized.NameValueCollection.HasKeys


Gets a value indicating whether the NameValueCollection contains keys that are not null.
IsRestricted Tests whether the specified HTTP header can be set.
OnDeserialization Overridden:
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
Remove Overridden:
Removes the specified header from the collection.
Set Overridden:
Sets the specified header to the specified value.
ToByteArray Obsolete.
ToString Overridden:
Obsolete.
Protected Constructors
ctor #2 Overloaded:
.ctor(SerializationInfo serializationInfo, StreamingContext streamingContext)

Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.
Protected Properties
IsReadOnly
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Read-write

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.IsReadOnly


Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.
Protected Methods
AddWithoutValidate Inserts a header into the collection without checking whether the header is on the restricted header list.
BaseAdd
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseAdd


Adds an entry with the specified key and value into the NameObjectCollectionBase instance.
BaseClear
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseClear


Removes all entries from the NameObjectCollectionBase instance.
BaseGet
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseGet(int index)

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGet


Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.
BaseGet
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseGet(string name)

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGet


Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.
BaseGetAllKeys
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllKeys


Returns a String array that contains all the keys in the NameObjectCollectionBase instance.
BaseGetAllValues
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseGetAllValues()

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues


Returns an Object array that contains all the values in the NameObjectCollectionBase instance.
BaseGetAllValues
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseGetAllValues(Type type)

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues


Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.
BaseGetKey
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey


Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.
BaseHasKeys
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseHasKeys


Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.
BaseRemove
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemove


Removes the entries with the specified key from the NameObjectCollectionBase instance.
BaseRemoveAt
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemoveAt


Removes the entry at the specified index of the NameObjectCollectionBase instance.
BaseSet
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseSet(int index, object value)

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSet


Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.
BaseSet
(inherited from System.Collections.Specialized.NameObjectCollectionBase)
Overloaded:
BaseSet(string name, object value)

See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSet


Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
InvalidateCachedArrays
(inherited from System.Collections.Specialized.NameValueCollection)
See base class member description: System.Collections.Specialized.NameValueCollection.InvalidateCachedArrays


Resets the cached arrays of the collection to null.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.WebHeaderCollection Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the WebHeaderCollection class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public WebHeaderCollection();

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.
C# Syntax:
protected WebHeaderCollection(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

A SerializationInfo containing the information required to serialize the WebHeaderCollection.

streamingContext

A StreamingContext containing the source of the serialized stream associated with the new WebHeaderCollection.

Remarks
This constructor implements the ISerializable interface for the WebHeaderCollection class.
See also:
MSDN: serialization

Return to top


Property: AllKeys (read-only)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.AllKeys

Summary
Gets all the keys in the NameValueCollection.
C# Syntax:
public virtual string[] AllKeys {get;}
Remarks
If the collection is empty, this method returns an empty String array, not null.

The arrays returned by NameValueCollection.AllKeys are cached for better performance and are automatically refreshed when the collection changes. A derived class can invalidate the cached version by calling NameValueCollection.InvalidateCachedArrays, thereby forcing the arrays to be recreated.

See also:
NameValueCollection.GetKey | NameValueCollection.InvalidateCachedArrays

Return to top


Property: Count (read-only)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Count

Summary
Gets the number of key-and-value pairs contained in the NameObjectCollectionBase instance.
C# Syntax:
public virtual int Count {get;}
Implements:
ICollection.Count

Return to top


Property: IsReadOnly (read-write)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.IsReadOnly

Summary
Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.
C# Syntax:
protected bool IsReadOnly {get; set;}
Remarks
A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created.

Return to top


Overloaded Property: Item (read-only)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Item

Summary
Gets the entry at the specified index of the NameValueCollection.
C# Syntax:
public string this[int index] {get;}
Parameters:

index

The zero-based index of the entry to locate in the collection. The zero-based index of the entry to locate in the collection.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[index] .

This property cannot be set. To set the value at a specified index, use Item[GetKey(index)] .

Return to top


Overloaded Property: Item (read-write)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Item

Summary
Gets or sets the entry with the specified key in the NameValueCollection.
C# Syntax:
public string this[string name] {get; set;}
Parameters:

name

The String key of the entry to locate. The key can be null. The String key of the entry to locate. The key can be null.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
NotSupportedException The collection is read-only and the operation attempts to modify the collection.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[name] .

If the specified key already exists in the collection, setting this property overwrites the existing values with the specified value. To add the new value to the existing list of values, use the NameValueCollection.Add method.

If the specified key does not exist in the collection, setting this property creates a new entry using the specified key and the specified value.

Return to top


Property: Keys (read-only)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Keys

Summary
Gets a NameObjectCollectionBase.KeysCollection instance that contains all the keys in the NameObjectCollectionBase instance.
C# Syntax:
public virtual NameObjectCollectionBase.KeysCollection Keys {get;}

Return to top


Overloaded Method: Add(
   NameValueCollection c
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Add

Summary
Copies the entries in the specified NameValueCollection to the current NameValueCollection.
C# Syntax:
public void Add(
   NameValueCollection c
);
Parameters:

c

The NameValueCollection to copy to the current NameValueCollection.

Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.
ArgumentNullException col is null.
Remarks
If a key in c already exists in the target NameValueCollection instance, the associated value in c is added to the existing comma-separated list of values associated with the same key in the target NameValueCollection instance.
See also:
NameValueCollection.Set

Return to top


Overloaded Method: Add(
   string header
)
Summary
Inserts the specified header into the collection.
C# Syntax:
public void Add(
   string header
);
Parameters:

header

The header to add, with the name and value separated by a colon.

Exceptions
Exception Type Condition
ArgumentNullException header is blank.
ArgumentException header does not contain a colon (:) character

-or-

header is a restricted header that should be set with a property.

-or-

header is an invalid HTTP header name.

Remarks
The WebHeaderCollection.Add method inserts a new header into the list of header name/value pairs. The header value must be specified in the format "header:value".

If the header specified in header is already present in the collection, value is concatenated with the existing value.

Return to top


Overloaded Method: Add(
   string name,
   string value
)
Summary
Inserts a new header with the specified name and value into the collection.
C# Syntax:
public override void Add(
   string name,
   string value
);
Parameters:

name

The header to add to the collection.

value

The content of the header.

Exceptions
Exception Type Condition
ArgumentNullException name is blank.
ArgumentException header is a restricted header that must be set with a property setting.

-or-

header is an invalid HTTP header name.

Remarks
The WebHeaderCollection.Add method inserts a new header into the list of header name/value pairs.

If the header specified in header is already present, value is concatenated with the existing value.

Return to top


Method: AddWithoutValidate(
   string headerName,
   string headerValue
)
Summary
Inserts a header into the collection without checking whether the header is on the restricted header list.
C# Syntax:
protected void AddWithoutValidate(
   string headerName,
   string headerValue
);
Parameters:

headerName

The header to add to the collection.

headerValue

The content of the header.

Remarks
The WebHeaderCollection.AddWithoutValidate method adds a header to the collection without checking whether the header is on the restricted header list.

Notes to inheritors: Use the WebHeaderCollection.AddWithoutValidate method to add headers that are normally exposed through properties.

Return to top


Method: BaseAdd(
   string name,
   object value
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseAdd

Summary
Adds an entry with the specified key and value into the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseAdd(
   string name,
   object value
);
Parameters:

name

The String key of the entry to add. The key can be null. The String key of the entry to add. The key can be null.

value

The Object value of the entry to add. The value can be null. The Object value of the entry to add. The value can be null.

Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.

Return to top


Method: BaseClear()
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseClear

Summary
Removes all entries from the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseClear();
Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.
Remarks
NameObjectCollectionBase.Count is set to zero.

Return to top


Overloaded Method: BaseGet(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGet

Summary
Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.
C# Syntax:
protected object BaseGet(
   int index
);
Parameters:

index

The zero-based index of the value to get.

Return Value:
An Object that represents the value of the entry at the specified index.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.

Return to top


Overloaded Method: BaseGet(
   string name
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGet

Summary
Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.
C# Syntax:
protected object BaseGet(
   string name
);
Parameters:

name

The String key of the entry to get. The key can be null. The String key of the entry to get. The key can be null.

Return Value:
An Object that represents the value of the first entry with the specified key, if found; otherwise, null.
Remarks
If the collection contains multiple entries with the specified key, this method returns only the first entry. To get the values of subsequent entries with the same key, use the enumerator to iterate through the collection and compare the keys. This method returns null in the following cases: 1) if the specified key is not found; and 2) if the specified key is found and its associated value is null. This method does not distinguish between the two cases.
See also:
NameObjectCollectionBase.GetEnumerator

Return to top


Method: BaseGetAllKeys()
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllKeys

Summary
Returns a String array that contains all the keys in the NameObjectCollectionBase instance.
C# Syntax:
protected string[] BaseGetAllKeys();
Return Value:
A String array that contains all the keys in the NameObjectCollectionBase instance.

Return to top


Overloaded Method: BaseGetAllValues()
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues

Summary
Returns an Object array that contains all the values in the NameObjectCollectionBase instance.
C# Syntax:
protected object[] BaseGetAllValues();
Return Value:
An Object array that contains all the values in the NameObjectCollectionBase instance.

Return to top


Overloaded Method: BaseGetAllValues(
   Type type
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValues

Summary
Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.
C# Syntax:
protected object[] BaseGetAllValues(
   Type type
);
Parameters:

type

A Type that represents the type of array to return.

Return Value:
An array of the specified type that contains all the values in the NameObjectCollectionBase instance.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a valid Type.
See also:
Type

Return to top


Method: BaseGetKey(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey

Summary
Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.
C# Syntax:
protected string BaseGetKey(
   int index
);
Parameters:

index

The zero-based index of the key to get.

Return Value:
A String that represents the key of the entry at the specified index.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.

Return to top


Method: BaseHasKeys()
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseHasKeys

Summary
Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.
C# Syntax:
protected bool BaseHasKeys();
Return Value:
true if the NameObjectCollectionBase instance contains entries whose keys are not null; otherwise, false.

Return to top


Method: BaseRemove(
   string name
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemove

Summary
Removes the entries with the specified key from the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseRemove(
   string name
);
Parameters:

name

The String key of the entries to remove. The key can be null. The String key of the entries to remove. The key can be null.

Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.

-or-

The collection has a fixed size.

Remarks
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.

Return to top


Method: BaseRemoveAt(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemoveAt

Summary
Removes the entry at the specified index of the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseRemoveAt(
   int index
);
Parameters:

index

The zero-based index of the entry to remove.

Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
NotSupportedException The collection is read-only.

-or-

The collection has a fixed size.

Remarks
In collections of contiguous elements, such as lists, the elements that follow the removed element move up to occupy the vacated spot. If the collection is indexed, the indexes of the elements that are moved are also updated. This behavior does not apply to collections where elements are conceptually grouped into buckets, such as a hashtable.

Return to top


Overloaded Method: BaseSet(
   int index,
   object value
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSet

Summary
Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseSet(
   int index,
   object value
);
Parameters:

index

The zero-based index of the entry to set.

value

The Object that represents the new value of the entry to set. The value can be null. The Object that represents the new value of the entry to set. The value can be null.

Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.

Return to top


Overloaded Method: BaseSet(
   string name,
   object value
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSet

Summary
Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.
C# Syntax:
protected void BaseSet(
   string name,
   object value
);
Parameters:

name

The String key of the entry to set. The key can be null. The String key of the entry to set. The key can be null.

value

The Object that represents the new value of the entry to set. The value can be null. The Object that represents the new value of the entry to set. The value can be null.

Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.
Remarks
If the collection contains multiple entries with the specified key, this method sets only the first entry. To set the values of subsequent entries with the same key, use the enumerator to iterate through the collection and compare the keys.
See also:
NameObjectCollectionBase.GetEnumerator

Return to top


Method: Clear()
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Clear

Summary
Invalidates the cached arrays and removes all entries from the NameValueCollection.
C# Syntax:
public void Clear();
Exceptions
Exception Type Condition
NotSupportedException The collection is read-only.
See also:
NameValueCollection.InvalidateCachedArrays

Return to top


Method: CopyTo(
   Array dest,
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.CopyTo

Summary
Copies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
C# Syntax:
public void CopyTo(
   Array dest,
   int index
);
Parameters:

dest

The one-dimensional Array that is the destination of the elements copied from NameValueCollection. The Array must have zero-based indexing.

index

The zero-based index in dest at which copying begins.

Exceptions
Exception Type Condition
ArgumentNullException dest is null.
ArgumentOutOfRangeException index is less than zero.
ArgumentException dest is multidimensional.

-or-

index is equal to or greater than the length of dest.

-or-

The number of elements in the source NameValueCollection is greater than the available space from index to the end of the destination dest.

InvalidCastException The type of the source NameValueCollection cannot be cast automatically to the type of the destination dest.
Remarks
The specified array must be of a compatible type.

This method uses Array.Copy to copy the elements.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~WebHeaderCollection();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Get(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Get

Summary
Gets the values at the specified index of the NameValueCollection combined into one comma-separated list.
C# Syntax:
public virtual string Get(
   int index
);
Parameters:

index

The zero-based index of the entry that contains the values to get from the collection. The zero-based index of the entry that contains the values to get from the collection.

Return Value:
A String that contains a comma-separated list of the values at the specified index of the NameValueCollection, if found; otherwise, null.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
See also:
NameValueCollection.GetValues | NameValueCollection.AllKeys

Return to top


Overloaded Method: Get(
   string name
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.Get

Summary
Gets the values associated with the specified key from the NameValueCollection combined into one comma-separated list.
C# Syntax:
public virtual string Get(
   string name
);
Parameters:

name

The String key of the entry that contains the values to get. The key can be null. The String key of the entry that contains the values to get. The key can be null.

Return Value:
A String that contains a comma-separated list of the values associated with the specified key from the NameValueCollection, if found; otherwise, null.
See also:
NameValueCollection.GetValues | NameValueCollection.AllKeys

Return to top


Method: GetEnumerator()
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetEnumerator

Summary
Returns an enumerator that can iterate through the NameObjectCollectionBase.
C# Syntax:
public IEnumerator GetEnumerator();
Return Value:
An IEnumerator for the NameObjectCollectionBase instance.
Implements:
IEnumerable.GetEnumerator
Remarks
This enumerator returns the keys of the collection as strings.

Enumerators only allow reading the data in the collection. Enumerators cannot be used to modify the underlying collection.

Initially, the enumerator is positioned before the first element in the collection. IEnumerator.Reset also brings the enumerator back to this position. At this position, calling IEnumerator.Current throws an exception. Therefore, you must call IEnumerator.MoveNext to advance the enumerator to the first element of the collection before reading the value of IEnumerator.Current.

IEnumerator.Current returns the same object until either IEnumerator.MoveNext or IEnumerator.Reset is called. IEnumerator.MoveNext sets IEnumerator.Current to the next element.

After the end of the collection is passed, the enumerator is positioned after the last element in the collection, and calling IEnumerator.MoveNext returns false. If the last call to IEnumerator.MoveNext returned false, calling IEnumerator.Current throws an exception. To set IEnumerator.Current to the first element of the collection again, you can call IEnumerator.Reset followed by IEnumerator.MoveNext.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying or deleting elements, the enumerator is irrecoverably invalidated and the next call to IEnumerator.MoveNext or IEnumerator.Reset throws an InvalidOperationException. If the collection is modified between IEnumerator.MoveNext and IEnumerator.Current, IEnumerator.Current will return the element that it is set to, even if the enumerator is already invalidated.

The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetKey(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.GetKey

Summary
Gets the key at the specified index of the NameValueCollection.
C# Syntax:
public virtual string GetKey(
   int index
);
Parameters:

index

The zero-based index of the key to get from the collection. The zero-based index of the key to get from the collection.

Return Value:
A String that contains the key at the specified index of the NameValueCollection, if found; otherwise, null.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
See also:
NameValueCollection.AllKeys

Return to top


Method: GetObjectData(
   SerializationInfo info,
   StreamingContext context
)
Inherited
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetObjectData

Summary
Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance.
C# Syntax:
public virtual void GetObjectData(
   SerializationInfo info,
   StreamingContext context
);
Parameters:

info

A SerializationInfo object that contains the information required to serialize the NameObjectCollectionBase instance.

context

A StreamingContext object that contains the source and destination of the serialized stream associated with the NameObjectCollectionBase instance.

Exceptions
Exception Type Condition
ArgumentNullException info is null.
Implements:
ISerializable.GetObjectData
See also:
ISerializable | SerializationInfo | StreamingContext

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetValues(
   int index
)
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.GetValues

Summary
Gets the values at the specified index of the NameValueCollection.
C# Syntax:
public virtual string[] GetValues(
   int index
);
Parameters:

index

The zero-based index of the entry that contains the values to get from the collection. The zero-based index of the entry that contains the values to get from the collection.

Return Value:
A String array that contains the values at the specified index of the NameValueCollection, if found; otherwise, null.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
See also:
NameValueCollection.Get | NameValueCollection.AllKeys

Return to top


Overloaded Method: GetValues(
   string header
)
Summary
Gets an array of header values stored in a header.
C# Syntax:
public override string[] GetValues(
   string header
);
Parameters:

header

The header to return.

Return Value:
An array of header strings.
Remarks
WebHeaderCollection.GetValues returns the contents of the specified header as an array.

Return to top


Method: HasKeys()
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.HasKeys

Summary
Gets a value indicating whether the NameValueCollection contains keys that are not null.
C# Syntax:
public bool HasKeys();
Return Value:
true if the NameValueCollection contains keys that are not null; otherwise, false.

Return to top


Method: InvalidateCachedArrays()
Inherited
See base class member description: System.Collections.Specialized.NameValueCollection.InvalidateCachedArrays

Summary
Resets the cached arrays of the collection to null.
C# Syntax:
protected void InvalidateCachedArrays();
Remarks
The arrays returned by NameValueCollection.AllKeys are cached for better performance and are automatically refreshed when the collection changes. A derived class can invalidate the cached version by calling NameValueCollection.InvalidateCachedArrays, thereby forcing the arrays to be recreated.
See also:
NameValueCollection.AllKeys

Return to top


Method: IsRestricted(
   string headerName
)
Summary
Tests whether the specified HTTP header can be set.
C# Syntax:
public static bool IsRestricted(
   string headerName
);
Parameters:

headerName

The header to test.

Return Value:
true if the header is restricted; otherwise false.
Exceptions
Exception Type Condition
ArgumentNullException headerName is null.
Remarks
The WebHeaderCollection.IsRestricted method returns true to indicate that a header is restricted and must be set using properties instead of directly. The restricted headers are:

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: OnDeserialization(
   object sender
)
Summary
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
C# Syntax:
public override void OnDeserialization(
   object sender
);
Parameters:

sender

Implements:
IDeserializationCallback.OnDeserialization

Return to top


Overridden Method: Remove(
   string name
)
Summary
Removes the specified header from the collection.
C# Syntax:
public override void Remove(
   string name
);
Parameters:

name

The name of the header to remove from the collection.

Exceptions
Exception Type Condition
ArgumentNullException name is null.
ArgumentException name is a restricted header.
Remarks
WebHeaderCollection.Remove deletes the specified header from the collection. If the same header was added multiple times with WebHeaderCollection.Add, a single call to WebHeaderCollection.Remove deletes all the headers.

Return to top


Overridden Method: Set(
   string name,
   string value
)
Summary
Sets the specified header to the specified value.
C# Syntax:
public override void Set(
   string name,
   string value
);
Parameters:

name

The header to set.

value

The content of the header to set.

Exceptions
Exception Type Condition
ArgumentNullException name is null.
ArgumentException name is a restricted header.
Remarks
The WebHeaderCollection.Set method inserts a new header into the list of header name/value pairs. The header value must be specified in the format header:value.

If the header specified in header is already present, value replaces the existing value.

Return to top


Method: ToByteArray()
Summary
Obsolete.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public byte[] ToByteArray();

Return to top


Overridden Method: ToString()
Summary
Obsolete.
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
C# Syntax:
public override string ToString();

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.