HttpListenerPrefixCollection.CopyTo Method (Array, Int32)

Copies the contents of an HttpListenerPrefixCollection to the specified array.

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

void CopyTo (
	Array^ array, 
	int offset
public void CopyTo (
	Array array, 
	int offset
public function CopyTo (
	array : Array, 
	offset : int
Not applicable.



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;

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