本文整理汇总了VB.NET中System.Collections.Generic.List<T>.AsReadOnly方法的典型用法代码示例。如果您正苦于以下问题:VB.NET List<T>.AsReadOnly方法的具体用法?VB.NET List<T>.AsReadOnly怎么用?VB.NET List<T>.AsReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List<T>
的用法示例。
在下文中一共展示了List<T>.AsReadOnly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Collections.Generic
Public Class Example
Public Shared Sub Main()
Dim dinosaurs As New List(Of String)(4)
Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)
dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Mamenchisaurus")
dinosaurs.Add("Deinonychus")
Console.WriteLine()
For Each dinosaur As String In dinosaurs
Console.WriteLine(dinosaur)
Next
Console.WriteLine(vbLf & _
"Dim roDinosaurs As IList(Of String) = dinosaurs.AsReadOnly")
Dim roDinosaurs As IList(Of String) = dinosaurs.AsReadOnly
Console.WriteLine(vbLf & "Elements in the read-only IList:")
For Each dinosaur As String In roDinosaurs
Console.WriteLine(dinosaur)
Next
Console.WriteLine(vbLf & "dinosaurs(2) = ""Coelophysis""")
dinosaurs(2) = "Coelophysis"
Console.WriteLine(vbLf & "Elements in the read-only IList:")
For Each dinosaur As String In roDinosaurs
Console.WriteLine(dinosaur)
Next
End Sub
End Class
输出:
Capacity: 4 Tyrannosaurus Amargasaurus Mamenchisaurus Deinonychus Dim roDinosaurs As IList(Of String) = dinosaurs.AsReadOnly Elements in the read-only IList: Tyrannosaurus Amargasaurus Mamenchisaurus Deinonychus dinosaurs(2) = "Coelophysis" Elements in the read-only IList: Tyrannosaurus Amargasaurus Coelophysis Deinonychus