Vb.net SortedDictionary键和值在某些地方有数组方法,但在其他地方没有
我正在尝试对结构的Vb.net SortedDictionary键和值在某些地方有数组方法,但在其他地方没有,vb.net,generics,collections,Vb.net,Generics,Collections,我正在尝试对结构的SortedDictionary进行线性插值计算,如下所示:- 主程序 Imports Measurements.Measurements Public Class Form1 Private Sub Button1_Click( sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim mydic As SortedDictionary(Of Distance, Temp
SortedDictionary
进行线性插值计算,如下所示:-
主程序
Imports Measurements.Measurements
Public Class Form1
Private Sub Button1_Click( sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim mydic As SortedDictionary(Of Distance, Temperature) =
New SortedDictionary(Of Distance, Temperature)
mydic.Add(Distance.FromMetres(20), Temperature.FromCentigrade(30))
mydic.Add(Distance.FromMetres(0), Temperature.FromCentigrade(10))
Dim dicinterpolated_temperature As Temperature = DicInterpolate
(Distance.FromMetres(7),
mydic)
End Sub
Public Function DicInterpolate (Of YType As {Structure, IMeasurements}, _
XType As {Structure, IMeasurements}) _
(ByVal x_value As XType,
ByVal sorted_dictionary As SortedDictionary(Of XType, YType)) _
As YType
Return Interpolate (x_value,
sorted_dictionary.Keys.ToArray,
sorted_dictionary.Values.ToArray)
End Function
End Class
其中,Distance
和Temperature
是实现i可比较
和i测量
等功能的结构,并在测量
命名空间中定义。此调用调用度量
项目中的函数,因此
Imports System.Collections.Generic
Namespace Measurements
Public Module Interpolation
Public Function Interpolate (Of YType As {Structure, IMeasurements}, _
XType As {Structure, IMeasurements}) _
(ByVal x3 As XType,
ByVal x_values() As XType, _
ByVal y_values() As YType) _
As YType
' calculate the answer and return it.
End Function
End Module
End Namespace
到目前为止,一切顺利。这一切都很好。但是,当我试图将DicInterpolate函数推送到它真正所属的度量名称空间时,我在这一行得到了编译错误:-
Return Interpolate (x_value,
sorted_dictionary.Keys.ToArray,
sorted_dictionary.Values.ToArray)
报告的错误有:-
'ToArray' is not a member of System.Collections.Generic.SortedDictionary(Of XType, YType).KeyCollection
'ToArray' is not a member of System.Collections.Generic.SortedDictionary(Of XType, YType).ValueCollection
有人知道为什么会这样,我能做些什么吗?是属于System.Linq
命名空间的扩展方法。因此,您必须添加引用并在全局(在项目设置中)或VB文件顶部添加Imports System.Linq