1
我正在嘗試使用VB.NET創建一個Quicksort基類,並將它放入一個IComparable元素的數組中。簽名是這樣的:將雙數組轉換爲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文檔指出翻一番的實現IComparable。爲什麼.NET編譯器不讓我這樣做?
哦,對。實際上,我應該使用這些新的語言功能。 – 2008-10-15 20:48:54