zoukankan      html  css  js  c++  java
  • Tuple

    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();
            }
        }

     

  • 相关阅读:
    luogu P3398 仓鼠找sugar
    关于lca
    luogu P3374 【模板】树状数组 1
    [NOIp2013普及组]车站分级
    [HDU1598]find the most comfortable road
    [NOI2015]程序自动分析
    [USACO08DEC]Secret Message
    [洛谷3375]【模板】KMP字符串匹配
    [ZJOI2010]网络扩容
    [SCOI2007]修车
  • 原文地址:https://www.cnblogs.com/lgxlsm/p/7504298.html
Copyright © 2011-2022 走看看