如何在 C# 中使用整数 return 类型的用户定义方法中的 return 语句 return 多个整数值?
How to return more than one integer values with a return statement in a user-defined method with integer return type in C#?
namespace MyApp
{
class Program
{
static int check(int id, int age)
{
return id,age; // adding age gives error
}
public static void Main(string[] args)
{
check(3064,24);
}
}
}
通过使用元组:
static (int, int) check(int id, int age)
{
return (id,age);
}
您还可以命名元组中的值:
static (int id, int age) check(int id, int age)
{
return (id,age);
}
namespace MyApp
{
class Program
{
static int check(int id, int age)
{
return id,age; // adding age gives error
}
public static void Main(string[] args)
{
check(3064,24);
}
}
}
通过使用元组:
static (int, int) check(int id, int age)
{
return (id,age);
}
您还可以命名元组中的值:
static (int id, int age) check(int id, int age)
{
return (id,age);
}