這應該在大多數情況下工作,但如果您不分配轉換委託可能會引發異常。
public static TResult[,] Convert<TSource, TResult>(
this TSource[,] array, Func<TSource, TResult> conversion = null) {
if(array == null) throw new ArgumentNullException("array");
if (conversion == null) {
var resultType = typeof(TResult);
conversion = source => (TResult)System.Convert.ChangeType(source, resultType);
}
var width = array.GetLength(1);
var height = array.GetLength(0);
var result = new TResult[height, width];
for (int i = 0; i < height; ++i)
for (int j = 0; j < width; ++j)
result[i, j] = conversion(array[i, j]);
return result;
}
有沒有「快速」的方式來做到這一點。如果這是你想要的,你必須將所有的數據複製到一個新的數組中。 – Gabe 2011-02-22 20:30:17
我很害怕這個。那麼.NET 4.0呢?會不會有一種安全的Office Interop類型? – ja72 2011-02-22 20:31:45
快速地在「no cpu」中或像在「單行語句」中那樣快速 – rene 2011-02-22 20:32:48