码迷,mamicode.com
首页 > 其他好文 > 详细

Tuple

时间:2017-09-11 13:07:53      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:read   main   ring   rest   item   rgs   嵌套   tuple   span   

Tuple

Tuple是C# 4.0时出的新特性,.Net Framework 4.0以上版本可用。
默认情况.Net Framework元组仅支持1到7个元组元素,如果有8个元素或者更多,需要使用Tuple的嵌套和Rest属性去实现。另外Tuple类提供创造元组对象的静态方法。

    class Program
    {
        static void Main(string[] args)
        {
            var testTuple1 = new Tuple<int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);
            Console.WriteLine($"Item 1: {testTuple1.Item1}, Item 6: {testTuple1.Item6}");
            var testTuple2 = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>(1, 2, 3, 4, 5, 6, 7, new Tuple<int, int, int>(8, 9, 10));
            Console.WriteLine($"Item 1: {testTuple2.Item1}, Item 10: {testTuple2.Rest.Item3}");

            var testTuple3 = Tuple.Create<int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);
            Console.WriteLine($"Item 1: {testTuple3.Item1}, Item 6: {testTuple3.Item6}");
            var testTuple4 = Tuple.Create<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);
            Console.WriteLine($"Item 1: {testTuple4.Item1}, Item 8: {testTuple4.Rest.Item1}");
            Console.ReadLine();
        }
    }

 

 

Tuple

标签:read   main   ring   rest   item   rgs   嵌套   tuple   span   

原文地址:http://www.cnblogs.com/lgxlsm/p/7504298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!