HttpListenerPrefixCollection.CopyTo Method (Array, Int32)

Note: This method is new in the .NET Framework version 2.0.

Copies the contents of an HttpListenerPrefixCollection to the specified array.

Namespace: System.Net
Assembly: System (in system.dll)

public void CopyTo (
	Array array,
	int offset
public void CopyTo (
	Array array, 
	int offset
public function CopyTo (
	array : Array, 
	offset : int



The one dimensional Array that receives the Uniform Resource Identifier (URI) prefix strings in this collection.


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

Exception typeCondition


array has more than one dimension.


This collection contains more elements than can be stored in array starting at offset.


The HttpListener associated with this collection is closed.


array cannot store string values.

The array must be able to contain strings and cannot be multidimensional.

The following code example copies the prefixes in a HttpListenerPrefixCollection.

public static string[] CopyPrefixes (HttpListener listener)
     HttpListenerPrefixCollection prefixes = listener.Prefixes;
     string[] prefixArray = new string[prefixes.Count];
     prefixes.CopyTo(prefixArray, 0);
     return prefixArray;

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions