如何遍历C#元组?
首先,声明一个元组并添加值-
Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom");
使用C#,要遍历元组,您可以使用单个元素-
tuple.Item1 // first itemtuple.Item2 // second item
To display the complete tuple, just use:
//显示整个元组
Console.WriteLine(tuple);
让我们看完整的代码-
示例
using System;using System.Threading;
namespace Demo {
class Program {
static void Main(string[] args) {
Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom");
if (tuple.Item1 == 100) {
Console.WriteLine(tuple.Item1);
}
if (tuple.Item2 == "Tom") {
Console.WriteLine(tuple.Item2);
}
//显示整个元组
Console.WriteLine(tuple);
}
}
}
以上是 如何遍历C#元组? 的全部内容, 来源链接: utcz.com/z/354925.html