转载一篇比较详细的描述元组的文章。
https://www.cnblogs.com/lavender000/p/6916157.html
Tuple是元组类,引用类型,多返回值可以这么用。
static Tuple<string, int, uint> GetStudentInfo(string name)
{
return new Tuple<string, int, uint>(“Bob”, 28, 175);
}
ValueTuple是值元组,值类型,多返回值可以这么用。
static ValueTuple<string, int, uint> GetStudentInfo(string name)
{
return new ValueTuple <string, int, uint>(“Bob”, 28, 175);
}
也可以这么用,
static (string, int, uint) GetStudentInfo(string name)
{
return (“Bob”, 28, 175);
}
var stu = GetStudentInfo(“Bob”); Console.WriteLine(stu.Item1);
也可以这么用
static (string name, int age, uint height) GetStudentInfo(string name)
{
return (“Bob”, 28, 175);
}
var stu = GetStudentInfo(“Bob”); Console.WriteLine(stu.name);
ValueTuple使用上有更方便的语法。
具体的使用还是看上面这篇文章或者访问官方文档。