CodeStatementCollection Class
Represents a collection of CodeStatement objects.
For a list of all members of this type, see CodeStatementCollection Members.
System.Object
System.Collections.CollectionBase
System.CodeDom.CodeStatementCollection
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeStatementCollection Inherits CollectionBase [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeStatementCollection : CollectionBase [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeStatementCollection : public CollectionBase [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeStatementCollection 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 CodeStatementCollection class provides a simple collection object that can be used to store a set of CodeStatement objects.
Example
[Visual Basic] ' Creates an empty CodeStatementCollection. Dim collection As New CodeStatementCollection() ' Adds a CodeStatement to the collection. collection.Add(New CodeCommentStatement("Test comment statement")) ' Adds an array of CodeStatement objects to the collection. Dim statements As CodeStatement() = {New CodeCommentStatement("Test comment statement"), New CodeCommentStatement("Test comment statement")} collection.AddRange(statements) ' Adds a collection of CodeStatement objects to the collection. Dim statementsCollection As New CodeStatementCollection() statementsCollection.Add(New CodeCommentStatement("Test comment statement")) statementsCollection.Add(New CodeCommentStatement("Test comment statement")) collection.AddRange(statementsCollection) ' Tests for the presence of a CodeStatement in the ' collection, and retrieves its index if it is found. Dim testStatement = New CodeCommentStatement("Test comment statement") Dim itemIndex As Integer = -1 If collection.Contains(testStatement) Then itemIndex = collection.IndexOf(testStatement) End If ' Copies the contents of the collection beginning at index 0 to the specified CodeStatement array. ' 'statements' is a CodeStatement array. collection.CopyTo(statements, 0) ' Retrieves the count of the items in the collection. Dim collectionCount As Integer = collection.Count ' Inserts a CodeStatement at index 0 of the collection. collection.Insert(0, New CodeCommentStatement("Test comment statement")) ' Removes the specified CodeStatement from the collection. Dim statement = New CodeCommentStatement("Test comment statement") collection.Remove(statement) ' Removes the CodeStatement at index 0. collection.RemoveAt(0) [C#] // Creates an empty CodeStatementCollection. CodeStatementCollection collection = new CodeStatementCollection(); // Adds a CodeStatement to the collection. collection.Add( new CodeCommentStatement("Test comment statement") ); // Adds an array of CodeStatement objects to the collection. CodeStatement[] statements = { new CodeCommentStatement("Test comment statement"), new CodeCommentStatement("Test comment statement") }; collection.AddRange( statements ); // Adds a collection of CodeStatement objects to the collection. CodeStatementCollection statementsCollection = new CodeStatementCollection(); statementsCollection.Add( new CodeCommentStatement("Test comment statement") ); statementsCollection.Add( new CodeCommentStatement("Test comment statement") ); collection.AddRange( statementsCollection ); // Tests for the presence of a CodeStatement in the // collection, and retrieves its index if it is found. CodeStatement testStatement = new CodeCommentStatement("Test comment statement"); int itemIndex = -1; if( collection.Contains( testStatement ) ) itemIndex = collection.IndexOf( testStatement ); // Copies the contents of the collection beginning at index 0 to the specified CodeStatement array. // 'statements' is a CodeStatement array. collection.CopyTo( statements, 0 ); // Retrieves the count of the items in the collection. int collectionCount = collection.Count; // Inserts a CodeStatement at index 0 of the collection. collection.Insert( 0, new CodeCommentStatement("Test comment statement") ); // Removes the specified CodeStatement from the collection. CodeStatement statement = new CodeCommentStatement("Test comment statement"); collection.Remove( statement ); // Removes the CodeStatement at index 0. collection.RemoveAt(0); [C++] // Creates an empty CodeStatementCollection. CodeStatementCollection* collection = new CodeStatementCollection(); // Adds a CodeStatement to the collection. collection->Add( new CodeCommentStatement(S"Test comment statement") ); // Adds an array of CodeStatement objects to the collection. CodeStatement* statements[] = { new CodeCommentStatement(S"Test comment statement"), new CodeCommentStatement(S"Test comment statement") }; collection->AddRange( statements ); // Adds a collection of CodeStatement objects to the collection. CodeStatementCollection* statementsCollection = new CodeStatementCollection(); statementsCollection->Add( new CodeCommentStatement(S"Test comment statement") ); statementsCollection->Add( new CodeCommentStatement(S"Test comment statement") ); collection->AddRange( statementsCollection ); // Tests for the presence of a CodeStatement in the // collection, and retrieves its index if it is found. CodeStatement* testStatement = new CodeCommentStatement(S"Test comment statement"); int itemIndex = -1; if( collection->Contains( testStatement ) ) itemIndex = collection->IndexOf( testStatement ); // Copies the contents of the collection beginning at index 0 to the specified CodeStatement array. // 'statements' is a CodeStatement array. collection->CopyTo( statements, 0 ); // Retrieves the count of the items in the collection. int collectionCount = collection->Count; // Inserts a CodeStatement at index 0 of the collection. collection->Insert( 0, new CodeCommentStatement(S"Test comment statement") ); // Removes the specified CodeStatement from the collection. CodeStatement* statement = new CodeCommentStatement(S"Test comment statement"); collection->Remove( statement ); // Removes the CodeStatement 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
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
CodeStatementCollection Members | System.CodeDom Namespace | CodeStatement