【发布时间】:2015-02-12 15:28:54
【问题描述】:
我正在尝试对 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 是实现IComparable 和IMeasurements 的结构,并在Measurements 命名空间中定义。此调用调用Measurements 项目中的一个函数,因此...
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 函数推送到它真正所属的 Measurements 命名空间中时,我在这一行得到编译错误:-
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
有谁知道为什么会这样,我能做些什么?
【问题讨论】:
标签: vb.net generics collections