我想创建一个能够使用我在 Vector 类(MathNet)上创建的多个扩展的方法。例如,我有 Vector 扩展:
public static bool IsNaN(this Vector<double> m)
{
int i = Array.IndexOf(m.ToArray(), double.NaN);
bool b = (i == -1);
b = !b;
return b;
}
我希望能够将此扩展用作参数。例如,我想写一些类似的东西:
public static Vector<double> ApplyExtension(this Matrix<double> x, VectorExtension myOperation)
{
Vector<double> res = new DenseVector(x.ColumnCount, 0);
for (int i = 0; i < x.ColumnCount; i++)
{
res[i] = x.Row(i).myOperation();
}
return res;
}
当然,“VectorExtension”不是一个定义明确的类型。我试图创建一个代表:
public delegate double VectorExtension(this Vector<double> d);
但是,它不起作用。有人可以帮助我吗?非常感谢!