HttpListenerPrefixCollection.CopyTo Method (String[], Int32)

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

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

public void CopyTo (
	string[] array,
	int offset
public final void CopyTo (
	String[] array, 
	int offset
public final function CopyTo (
	array : String[], 
	offset : int
Not applicable.



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;

public static String[] CopyPrefixes(HttpListener listener)
    HttpListenerPrefixCollection prefixes = listener.get_Prefixes();
    String prefixArray[] = new String[prefixes.get_Count()];
    prefixes.CopyTo(prefixArray, 0);
    return prefixArray;
} //CopyPrefixes

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions