Editéieren

CodeStatementCollection Class

Definition

Represents a collection of CodeStatement objects.

public ref class CodeStatementCollection : System::Collections::CollectionBase
public class CodeStatementCollection : System.Collections.CollectionBase
type CodeStatementCollection = class
    inherit CollectionBase
Public Class CodeStatementCollection
Inherits CollectionBase
Inheritance
CodeStatementCollection

Examples

The following example demonstrates how to use the CodeStatementCollection class. The example creates a new instance of the class and uses several methods to add statements to the collection, return their index, and add or remove statements at a specific index point.

// 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.
CodeStatement testStatement = new CodeCommentStatement("Test comment statement");
CodeStatementCollection statementsCollection = new CodeStatementCollection();
statementsCollection.Add( new CodeCommentStatement("Test comment statement") );
statementsCollection.Add( new CodeCommentStatement("Test comment statement") );
statementsCollection.Add( testStatement );

collection.AddRange( statementsCollection );

// Tests for the presence of a CodeStatement in the
// collection, and retrieves its index if it is found.
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.
CodeStatement[] statementArray = new CodeStatement[collection.Count];
collection.CopyTo( statementArray, 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.
collection.Remove( testStatement );

// Removes the CodeStatement at index 0.
collection.RemoveAt(0);
' 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 testStatement As New CodeStatement
Dim statementsCollection As New CodeStatementCollection
statementsCollection.Add(New CodeCommentStatement("Test comment statement"))
statementsCollection.Add(New CodeCommentStatement("Test comment statement"))
statementsCollection.Add(testStatement)
collection.AddRange(statementsCollection)

' Tests for the presence of a CodeStatement in the 
' collection, and retrieves its index if it is found.
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.
Dim statementArray(collection.Count - 1) As CodeStatement
collection.CopyTo(statementArray, 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.
collection.Remove(testStatement)

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

Remarks

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

Constructors

Name Description
CodeStatementCollection()

Initializes a new instance of the CodeStatementCollection class.

CodeStatementCollection(CodeStatement[])

Initializes a new instance of the CodeStatementCollection class that contains the specified array of CodeStatement objects.

CodeStatementCollection(CodeStatementCollection)

Initializes a new instance of the CodeStatementCollection class that contains the elements of the specified source collection.

Properties

Name Description
Item[Int32]

Gets or sets the CodeStatement object at the specified index in the collection.

Methods

Name Description
Add(CodeExpression)

Adds the specified CodeExpression object to the collection.

Add(CodeStatement)

Adds the specified CodeStatement object to the collection.

AddRange(CodeStatement[])

Adds a set of CodeStatement objects to the collection.

AddRange(CodeStatementCollection)

Adds the contents of another CodeStatementCollection object to the end of the collection.

Contains(CodeStatement)

Gets a value that indicates whether the collection contains the specified CodeStatement object.

CopyTo(CodeStatement[], Int32)

Copies the elements of the CodeStatementCollection object to a one-dimensional Array instance, starting at the specified index.

IndexOf(CodeStatement)

Gets the index of the specified CodeStatement object in the CodeStatementCollection, if it exists in the collection.

Insert(Int32, CodeStatement)

Inserts the specified CodeStatement object into the collection at the specified index.

Remove(CodeStatement)

Removes the specified CodeStatement object from the collection.

Applies to

See also