我通过我通常用来将 C# 转换为 VB.NET 的工具运行了您提到的示例,网址为 www.developerfusion.co.uk/tools
Imports System
Imports System.Collections.Generic
Imports System.Text
Namespace ConsoleApplication1
Class PairCollection(Of TKey, TValue)
Inherits List(Of KeyValuePair(Of TKey, TValue))
Public Sub Add(ByVal key As TKey, ByVal value As TValue)
Me.Add(New KeyValuePair(Of TKey, TValue)(key, value))
End Sub
Public Function FindByKey(ByVal key As TKey) As List(Of KeyValuePair(Of TKey, TValue))
Return Me.FindAll(Function(ByVal item As KeyValuePair(Of TKey, TValue)) (item.Key.Equals(key)))
End Function
Public Function FindByValue(ByVal value As TValue) As List(Of KeyValuePair(Of TKey, TValue))
Return Me.FindAll(Function(ByVal item As KeyValuePair(Of TKey, TValue)) (item.Value.Equals(value)))
End Function
End Class
Class Program
Private Shared Sub Main(ByVal args As String())
Dim menu As New PairCollection(Of String, Double)()
menu.Add("Burger", 3.5R)
menu.Add("Hot Dog", 2.25)
menu.Add("Fries", 1.75)
Console.WriteLine(menu.FindByKey("Fries")(0))
Console.ReadLine()
End Sub
End Class
End Namespace
如您所见, Add() 方法与您的方法略有不同。