This documentation is archived and is not being maintained.

CodeNamespaceCollection Class

Represents a collection of CodeNamespace objects.

For a list of all members of this type, see CodeNamespaceCollection Members.

System.Object
   System.Collections.CollectionBase
      System.CodeDom.CodeNamespaceCollection

[Visual Basic]
<Serializable>
<ClassInterface(ClassInterfaceType.AutoDispatch)>
<ComVisible(True)>
Public Class CodeNamespaceCollection
   Inherits CollectionBase
[C#]
[Serializable]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class CodeNamespaceCollection : CollectionBase
[C++]
[Serializable]
[ClassInterface(ClassInterfaceType::AutoDispatch)]
[ComVisible(true)]
public __gc class CodeNamespaceCollection : public
   CollectionBase
[JScript]
public
   Serializable
 ClassInterface(ClassInterfaceType.AutoDispatch)
 ComVisible(true)
class CodeNamespaceCollection extends CollectionBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The CodeNamespaceCollection class provides a simple collection object that can be used to store a set of CodeNamespace objects.

Example

[Visual Basic] 
' Creates an empty CodeNamespaceCollection.            
Dim collection As New CodeNamespaceCollection()

' Adds a CodeNamespace to the collection.
collection.Add(New CodeNamespace("TestNamespace"))

' Adds an array of CodeNamespace objects to the collection.
Dim namespaces As CodeNamespace() = {New CodeNamespace("TestNamespace1"), New CodeNamespace("TestNamespace2")}
collection.AddRange(namespaces)

' Adds a collection of CodeNamespace objects to the collection.
Dim namespacesCollection As New CodeNamespaceCollection()
namespacesCollection.Add(New CodeNamespace("TestNamespace1"))
namespacesCollection.Add(New CodeNamespace("TestNamespace2"))
collection.AddRange(namespacesCollection)

' Tests for the presence of a CodeNamespace in the collection,
' and retrieves its index if it is found.
Dim testNamespace As New CodeNamespace("TestNamespace")
Dim itemIndex As Integer = -1
If collection.Contains(testNamespace) Then
    itemIndex = collection.IndexOf(testNamespace)
End If

' Copies the contents of the collection beginning at index 0,
' to the specified CodeNamespace array.
' 'namespaces' is a CodeNamespace array.
collection.CopyTo(namespaces, 0)

' Retrieves the count of the items in the collection.
Dim collectionCount As Integer = collection.Count

' Inserts a CodeNamespace at index 0 of the collection.
collection.Insert(0, New CodeNamespace("TestNamespace"))

' Removes the specified CodeNamespace from the collection.
Dim namespace_ As New CodeNamespace("TestNamespace")
collection.Remove(namespace_)

' Removes the CodeNamespace at index 0.
collection.RemoveAt(0)

[C#] 
// Creates an empty CodeNamespaceCollection.            
CodeNamespaceCollection collection = new CodeNamespaceCollection();

// Adds a CodeNamespace to the collection.
collection.Add( new CodeNamespace("TestNamespace") );

// Adds an array of CodeNamespace objects to the collection.
CodeNamespace[] namespaces = { new CodeNamespace("TestNamespace1"), new CodeNamespace("TestNamespace2") };
collection.AddRange( namespaces );

// Adds a collection of CodeNamespace objects to the collection.
CodeNamespaceCollection namespacesCollection = new CodeNamespaceCollection();
namespacesCollection.Add( new CodeNamespace("TestNamespace1") );
namespacesCollection.Add( new CodeNamespace("TestNamespace2") );
collection.AddRange( namespacesCollection );

// Tests for the presence of a CodeNamespace in the collection,
// and retrieves its index if it is found.
CodeNamespace testNamespace = new CodeNamespace("TestNamespace");
int itemIndex = -1;
if( collection.Contains( testNamespace ) )
    itemIndex = collection.IndexOf( testNamespace );

// Copies the contents of the collection beginning at index 0,
// to the specified CodeNamespace array.
// 'namespaces' is a CodeNamespace array.
collection.CopyTo( namespaces, 0 );

// Retrieves the count of the items in the collection.
int collectionCount = collection.Count;

// Inserts a CodeNamespace at index 0 of the collection.
collection.Insert( 0, new CodeNamespace("TestNamespace") );

// Removes the specified CodeNamespace from the collection.
CodeNamespace namespace_ = new CodeNamespace("TestNamespace");
collection.Remove( namespace_ );

// Removes the CodeNamespace at index 0.
collection.RemoveAt(0);

[C++] 
// Creates an empty CodeNamespaceCollection.            
CodeNamespaceCollection* collection = new CodeNamespaceCollection();

// Adds a CodeNamespace to the collection.
collection->Add( new CodeNamespace(S"TestNamespace") );

// Adds an array of CodeNamespace objects to the collection.
CodeNamespace* namespaces[] = { new CodeNamespace(S"TestNamespace1"), new CodeNamespace(S"TestNamespace2") };
collection->AddRange( namespaces );

// Adds a collection of CodeNamespace objects to the collection.
CodeNamespaceCollection* namespacesCollection = new CodeNamespaceCollection();
namespacesCollection->Add( new CodeNamespace(S"TestNamespace1") );
namespacesCollection->Add( new CodeNamespace(S"TestNamespace2") );
collection->AddRange( namespacesCollection );

// Tests for the presence of a CodeNamespace in the collection,
// and retrieves its index if it is found.
CodeNamespace* testNamespace = new CodeNamespace(S"TestNamespace");
int itemIndex = -1;
if( collection->Contains( testNamespace ) )
    itemIndex = collection->IndexOf( testNamespace );

// Copies the contents of the collection beginning at index 0,
// to the specified CodeNamespace array.
// 'namespaces' is a CodeNamespace array.
collection->CopyTo( namespaces, 0 );

// Retrieves the count of the items in the collection.
int collectionCount = collection->Count;

// Inserts a CodeNamespace at index 0 of the collection.
collection->Insert( 0, new CodeNamespace(S"TestNamespace") );

// Removes the specified CodeNamespace from the collection.
CodeNamespace* namespace_ = new CodeNamespace(S"TestNamespace");
collection->Remove( namespace_ );

// Removes the CodeNamespace at index 0.
collection->RemoveAt(0);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.CodeDom

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

CodeNamespaceCollection Members | System.CodeDom Namespace | CodeNamespace

Show: