本文整理汇总了VB.NET中System.Collections.ObjectModel.Collection<T>.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Collection<T>.IndexOf方法的具体用法?VB.NET Collection<T>.IndexOf怎么用?VB.NET Collection<T>.IndexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObjectModel.Collection<T>
的用法示例。
在下文中一共展示了Collection<T>.IndexOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Demo
' 导入命名空间
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Public Class Demo
Public Shared Sub Main()
Dim dinosaurs As New Collection(Of String)
dinosaurs.Add("Psitticosaurus")
dinosaurs.Add("Caudipteryx")
dinosaurs.Add("Compsognathus")
dinosaurs.Add("Muttaburrasaurus")
Console.WriteLine("{0} dinosaurs:", dinosaurs.Count)
Display(dinosaurs)
Console.WriteLine(vbLf & "IndexOf(""Muttaburrasaurus""): {0}", _
dinosaurs.IndexOf("Muttaburrasaurus"))
Console.WriteLine(vbLf & "Contains(""Caudipteryx""): {0}", _
dinosaurs.Contains("Caudipteryx"))
Console.WriteLine(vbLf & "Insert(2, ""Nanotyrannus"")")
dinosaurs.Insert(2, "Nanotyrannus")
Display(dinosaurs)
Console.WriteLine(vbLf & "dinosaurs(2): {0}", dinosaurs(2))
Console.WriteLine(vbLf & "dinosaurs(2) = ""Microraptor""")
dinosaurs(2) = "Microraptor"
Display(dinosaurs)
Console.WriteLine(vbLf & "Remove(""Microraptor"")")
dinosaurs.Remove("Microraptor")
Display(dinosaurs)
Console.WriteLine(vbLf & "RemoveAt(0)")
dinosaurs.RemoveAt(0)
Display(dinosaurs)
Console.WriteLine(vbLf & "dinosaurs.Clear()")
dinosaurs.Clear()
Console.WriteLine("Count: {0}", dinosaurs.Count)
End Sub
Private Shared Sub Display(ByVal cs As Collection(Of String))
Console.WriteLine()
For Each item As String In cs
Console.WriteLine(item)
Next item
End Sub
End Class
输出:
4 dinosaurs: Psitticosaurus Caudipteryx Compsognathus Muttaburrasaurus IndexOf("Muttaburrasaurus"): 3 Contains("Caudipteryx"): True Insert(2, "Nanotyrannus") Psitticosaurus Caudipteryx Nanotyrannus Compsognathus Muttaburrasaurus dinosaurs(2): Nanotyrannus dinosaurs(2) = "Microraptor" Psitticosaurus Caudipteryx Microraptor Compsognathus Muttaburrasaurus Remove("Microraptor") Psitticosaurus Caudipteryx Compsognathus Muttaburrasaurus RemoveAt(0) Caudipteryx Compsognathus Muttaburrasaurus dinosaurs.Clear() Count: 0