內部實現,我發現上述的Array.Sort內,.NET 4.0的排序
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail), SecurityCritical]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool TrySZSort(Array keys, Array items, int left, int right);
被調用。 任何想法如何實現?
也就是說方法是在本機代碼來實現,因此'extern'關鍵字。可能會被引用到某個地方的引用源中,但除非您只是想了解它是如何實現的,否則它可能比您在託管代碼中編寫的任何東西都要快。 – 2012-08-14 00:57:48
http://stackoverflow.com/questions/6842090/c-sharp-fastest-way-to-sort-an-array-in-descending-order – xandercoded 2012-08-14 01:01:12
我很好奇,因爲天真的QuickSort被調用,除非使用默認的Comparer。那麼這意味着即使TrySZSort被調用,Array.Sort也不能保證N * Log(N)最壞的情況。 – 2012-08-14 01:01:22