C#中的元组剩余属性
通过在Rest属性中嵌套元组对象来创建包含八个或更多元素的元组。
元组看起来像-
Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>
上面,使用Rest属性添加了第8个元素。
让我们来看一个例子。
示例
using System;
public class Program {
public static void Main() {
var myTuple = Tuple.Create(1, 2.5M, "Tom", "100", 5, 10.5M, "Henry", "100");
Console.WriteLine("Item1 : "+ myTuple.Item1);
Console.WriteLine("Item2 : "+ myTuple.Item2);
Console.WriteLine("Item3 : "+ myTuple.Item3);
Console.WriteLine("Item4 : "+ myTuple.Item4);
Console.WriteLine("Item5 : "+ myTuple.Item5);
Console.WriteLine("Item6 : "+ myTuple.Item6);
Console.WriteLine("Item7 : "+ myTuple.Item7);
Console.WriteLine("Item8 : "+ myTuple.Rest);
}
}输出结果
Item1 : 1 Item2 : 2.5 Item3 : Tom Item4 : 100 Item5 : 5 Item6 : 10.5 Item7 : Henry Item8 : (100)
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语