在C#中获取元组元素的类型
要获取元组元素的类型,代码如下-
示例
using System;
public class Demo {
public static void Main(String[] args){
var tuple1 = Tuple.Create(150, 1500, Tuple.Create(50, 100));
var tuple2 = Tuple.Create(150, 1500, Tuple.Create(100, 200));
Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));
Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());
Console.WriteLine("Type of Tuple1 = "+tuple1.GetType());
Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());
Console.WriteLine("Type of Tuple1 = "+tuple2.GetType());
}
}输出结果
这将产生以下输出-
Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = 188892 Type of Tuple1 = System.Tuple`3[System.Int32,System.Int32,System.Tuple`2[System.Int32,System.Int32]] HashCode of Tuple2 = 191462 Type of Tuple1 = System.Tuple`3[System.Int32,System.Int32,System.Tuple`2[System.Int32,System.Int32]]
示例
现在让我们来看另一个示例-
using System;
public class Demo {
public static void Main(String[] args){
var tuple1 = Tuple.Create(10, 20);
var tuple2 = Tuple.Create(30, 40);
Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));
Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());
Console.WriteLine("Type of Tuple1 = "+tuple1.GetType());
Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());
Console.WriteLine("Type of Tuple1 = "+tuple2.GetType());
}
}输出结果
这将产生以下输出-
Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = 350 Type of Tuple1 = System.Tuple`2[System.Int32,System.Int32] HashCode of Tuple2 = 1014 Type of Tuple1 = System.Tuple`2[System.Int32,System.Int32]
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短