CodeStatementCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 CodeStatement 对象集合。
public ref class CodeStatementCollection : System::Collections::CollectionBase
public class CodeStatementCollection : System.Collections.CollectionBase
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeStatementCollection : System.Collections.CollectionBase
type CodeStatementCollection = class
inherit CollectionBase
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeStatementCollection = class
inherit CollectionBase
Public Class CodeStatementCollection
Inherits CollectionBase
- 继承
- 属性
示例
下面的示例演示如何使用 CodeStatementCollection 类。 该示例创建 类的新实例,并使用多种方法将语句添加到集合、返回其索引,以及在特定索引点添加或删除语句。
// Creates an empty CodeStatementCollection.
CodeStatementCollection^ collection = gcnew CodeStatementCollection;
// Adds a CodeStatement to the collection.
collection->Add( gcnew CodeCommentStatement( "Test comment statement" ) );
// Adds an array of CodeStatement objects to the collection.
array<CodeStatement^>^statements = {gcnew CodeCommentStatement( "Test comment statement" ),gcnew CodeCommentStatement( "Test comment statement" )};
collection->AddRange( statements );
// Adds a collection of CodeStatement objects to the collection.
CodeStatement^ testStatement = gcnew CodeCommentStatement( "Test comment statement" );
CodeStatementCollection^ statementsCollection = gcnew CodeStatementCollection;
statementsCollection->Add( gcnew CodeCommentStatement( "Test comment statement" ) );
statementsCollection->Add( gcnew 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.
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, gcnew 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.
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)
注解
CodeStatementCollection 类提供一个简单的集合对象,该对象可用于存储一组 CodeStatement 对象。
构造函数
CodeStatementCollection() |
初始化 CodeStatementCollection 类的新实例。 |
CodeStatementCollection(CodeStatement[]) |
初始化 CodeStatementCollection 类的新实例,该实例包含 CodeStatement 对象的指定数组。 |
CodeStatementCollection(CodeStatementCollection) |
初始化 CodeStatementCollection 类的新实例,该实例包含指定源集合的元素。 |
属性
Capacity |
获取或设置 CollectionBase 可包含的元素数。 (继承自 CollectionBase) |
Count |
获取 CollectionBase 实例中包含的元素数。 不能重写此属性。 (继承自 CollectionBase) |
InnerList |
获取一个 ArrayList,它包含 CollectionBase 实例中元素的列表。 (继承自 CollectionBase) |
Item[Int32] |
获取或设置集合中指定索引处的 CodeStatement 对象。 |
List |
获取一个 IList,它包含 CollectionBase 实例中元素的列表。 (继承自 CollectionBase) |
方法
显式接口实现
ICollection.CopyTo(Array, Int32) |
从目标数组的指定索引处开始将整个 CollectionBase 复制到兼容的一维 Array。 (继承自 CollectionBase) |
ICollection.IsSynchronized |
获取一个值,该值指示是否同步对 CollectionBase 的访问(线程安全)。 (继承自 CollectionBase) |
ICollection.SyncRoot |
获取可用于同步对 CollectionBase 的访问的对象。 (继承自 CollectionBase) |
IList.Add(Object) |
将对象添加到 CollectionBase 的结尾处。 (继承自 CollectionBase) |
IList.Contains(Object) |
确定 CollectionBase 是否包含特定元素。 (继承自 CollectionBase) |
IList.IndexOf(Object) |
搜索指定的 Object,并返回整个 CollectionBase 中第一个匹配项的从零开始的索引。 (继承自 CollectionBase) |
IList.Insert(Int32, Object) |
将元素插入 CollectionBase 的指定索引处。 (继承自 CollectionBase) |
IList.IsFixedSize |
获取一个值,该值指示 CollectionBase 是否具有固定大小。 (继承自 CollectionBase) |
IList.IsReadOnly |
获取一个值,该值指示 CollectionBase 是否为只读。 (继承自 CollectionBase) |
IList.Item[Int32] |
获取或设置指定索引处的元素。 (继承自 CollectionBase) |
IList.Remove(Object) |
从 CollectionBase 中移除特定对象的第一个匹配项。 (继承自 CollectionBase) |
扩展方法
Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定的类型。 |
OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |
AsParallel(IEnumerable) |
启用查询的并行化。 |
AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |