HttpListenerPrefixCollection.CopyTo Method (String[], Int32)

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

Copies the contents of an HttpListenerPrefixCollection to the specified string array.

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

Public Sub CopyTo ( _
	array As String(), _
	offset As Integer _
Dim instance As HttpListenerPrefixCollection
Dim array As String()
Dim offset As Integer

instance.CopyTo(array, offset)
public final void CopyTo (
	String[] array, 
	int offset
public final function CopyTo (
	array : String[], 
	offset : int



The one dimensional string 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.

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