简单来说就是一个各分量数据类型可以不同的多维向量
其可以作为一种数据类型,例如
(string country, string capital, double gdp) countryInfo ,访问直接用countryInfo.<propertyName>嫌麻烦直接用隐式变量命名即可
var countryInfo = ("China", "Beijing", 3000); ,此时直接用countryInfo.Item<X> 也能访问也可以作为一种快速赋值的方法
// 下面直接声明并初始化了三个变量 (string country, string capital, double gdp) = ("China", "Beijing", 3000); /* -- division -- */ string country; string capital; double gdp; (country, capital, gdp) = ("China", "Beijing", 3000);
// 从方法中返回元组 public (int, string) GetPerson() { return (1, "John Doe"); } var person = GetPerson(); Console.WriteLine(person.Item1); // 输出:1 Console.WriteLine(person.Item2); // 输出:John Doe
元组项的数据类型是硬编码的,在编译时决定,运行时不可改变
System.Tuple允许的最大项数为8
本质上:System.ValueTuple<…>