我正在尝试使用 VB.NET 创建一个 Quicksort 基类,并将其作为一组 IComparable 元素。签名如下所示:
public shared sub Sort(ByVal values() as IComparable)
但是,当我传入一个双精度数组时,编译器会给我错误。
Dim numbers(100) as double
Dim random as new Random(0)
for i as integer = 0 to numbers.length - 1
numbers(i) = random.NextDouble()
Next
QuickSort.Sort(numbers) ' gives compiler error.
错误是:
Error 88 Value of type '1-dimensional array of Double' cannot be converted to '1-dimensional array of System.IComparable' because 'Double' is not derived from 'System.IComparable'. C:\Proving Grounds\Module1.vb
.NET 文档说明 double 的实现 IComparable。为什么 .NET 编译器不让我这样做?