答案 0 :(得分:0)
根据Filip的建议,您可以使用Tuple返回多个整数:
public static Tuple<int, int, int, int, int> GeometryandControlPoints(int t, double rinn, double rout, int nx, int ny, int poly)
{
int nel, n, m, ncp, gdof;
nel = nx * ny;
n = nx + poly;
m = ny + poly;
ncp = n * m;
gdof = 2 * ncp;
return new Tuple<int, int, int, int, int>(nel,n, m, ncp, gdof);
}
另一种方法是创建一个自定义的 CLASS ,它封装了五个int并返回该int。
答案 1 :(得分:0)
是的,有可能。您应该使用ValueTuple。从C#7开始,您可以像这样重写方法:
public static (int nel, int n, int m, int ncp, int gdof) GeometryandControlPoints(int t, double rinn, double rout, int nx, int ny, int poly)
{
int nel, n, m, ncp, gdof;
// ...
return (nel, n, m, ncp, gdof);
}
然后使用它:
(var nel, var n, var m, var ncp, var gdof) = GeometryandControlPoints(…);
Console.WriteLine((nel, n, m, ncp, gdof));
或者这样:
var res = GeometryandControlPoints(…);
Console.WriteLine($"{res.nel}, {res.n}, {res.m}, {res.ncp}, {res.gdof}");