首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在c#中使用多个返回

如何在c#中使用多个返回
EN

Stack Overflow用户
提问于 2019-06-06 06:09:52
回答 1查看 115关注 0票数 -7

我是C#的新手。我想知道是否有可能在一个代码中有许多返回。我的代码目前不能工作。如下所示:

代码语言:javascript
复制
public static 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 (nel, n, m, ncp, gdof);
}

错误出现在return行上,如下图所示。

EN

回答 1

Stack Overflow用户

发布于 2019-06-06 07:00:11

按照Filip的建议,您可以使用Tuple返回多个int

代码语言:javascript
复制
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);
}

另一种方法是创建一个封装了5个int的自定义并返回它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56468696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档