Python NET调用C#方法并将null作为argumen传递

2024-10-01 13:34:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的静态C#方法

public static double[] TestMethod(double[] a, double[] b)

我想使用Python NET包从Python调用它。在

^{pr2}$

但是我如何为第一个或第二个参数传递null?在

t2 = MyStaticClass.MyTestMethod(None, [3., 4.]) # fails! TypeError: No method matches given arguments

t3 = MyStaticClass.MyTestMethod([1., 2.], None) # fails! TypeError: No method matches given arguments

我知道当参数a或beb是{}时,我可以添加额外的C方法。在

public static double[] TestMethodWithANull(double[] b)
{ return TestMethod(null, b); }

public static double[] TestMethodWithBNull(double[] a)
{ return TestMethod(a, null); }

但是我更愿意将一个null从Python传递到C方法。例如,{cd6}可以在MATLAB中传递。在


Tags: 方法nononestaticpublicnullmethodgiven