本文整理匯總了VB.NET中System.Collections.ObjectModel.ReadOnlyCollection<T>.Count屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET ReadOnlyCollection<T>.Count屬性的具體用法?VB.NET ReadOnlyCollection<T>.Count怎麽用?VB.NET ReadOnlyCollection<T>.Count使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Collections.ObjectModel.ReadOnlyCollection<T>
的用法示例。
在下文中一共展示了ReadOnlyCollection<T>.Count屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Public Class Example
Public Shared Sub Main()
Dim dinosaurs As New List(Of String)
dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Deinonychus")
dinosaurs.Add("Compsognathus")
Dim readOnlyDinosaurs As _
New ReadOnlyCollection(Of String)(dinosaurs)
Console.WriteLine()
For Each dinosaur As String In readOnlyDinosaurs
Console.WriteLine(dinosaur)
Next
Console.WriteLine(vbLf & "Count: {0}", _
readOnlyDinosaurs.Count)
Console.WriteLine(vbLf & "Contains(""Deinonychus""): {0}", _
readOnlyDinosaurs.Contains("Deinonychus"))
Console.WriteLine(vbLf & _
"readOnlyDinosaurs(3): {0}", readOnlyDinosaurs(3))
Console.WriteLine(vbLf & "IndexOf(""Compsognathus""): {0}", _
readOnlyDinosaurs.IndexOf("Compsognathus"))
Console.WriteLine(vbLf & "Insert into the wrapped List:")
Console.WriteLine("Insert(2, ""Oviraptor"")")
dinosaurs.Insert(2, "Oviraptor")
Console.WriteLine()
For Each dinosaur As String In readOnlyDinosaurs
Console.WriteLine(dinosaur)
Next
Dim dinoArray(readOnlyDinosaurs.Count + 1) As String
readOnlyDinosaurs.CopyTo(dinoArray, 1)
Console.WriteLine(vbLf & "Copied array has {0} elements:", _
dinoArray.Length)
For Each dinosaur As String In dinoArray
Console.WriteLine("""{0}""", dinosaur)
Next
End Sub
End Class
輸出:
Tyrannosaurus Amargasaurus Deinonychus Compsognathus Count: 4 Contains("Deinonychus"): True readOnlyDinosaurs(3): Compsognathus IndexOf("Compsognathus"): 3 Insert into the wrapped List: Insert(2, "Oviraptor") Tyrannosaurus Amargasaurus Oviraptor Deinonychus Compsognathus Copied array has 7 elements: "" "Tyrannosaurus" "Amargasaurus" "Oviraptor" "Deinonychus" "Compsognathus" ""