【发布时间】:2010-01-24 02:52:59
【问题描述】:
采用以下 C# 方法:
static double[] AddArrays(double[] left, double[] right)
{
if (left.Length != right.Length) {
throw new ArgumentException("Arrays to add are not the same length");
}
double[] result = new double[left.Length];
for (int i = 0; i < left.Length; i++) {
result[i] = left[i] + right[i];
}
return result;
}
据我了解,CLR 会将result 初始化为全零,尽管AddArrays 无论如何都将要完全初始化它。有什么办法可以避免这种额外的工作?即使这意味着使用不安全的 C#、C++/CLI 或原始 IL 代码?
编辑:由于here 所述的原因,无法完成。
【问题讨论】: