C#元組

C#元組

using System;

namespace 元組
{
    /// <summary>
    /// The .Net Framework directly supports tuples with one to seven elements.In addition,you can create
    /// tuples of eight or more elements by nesting tuple objects in the Rest Property
    /// </summary>
    class Program
    {
         

        static void Main(string[] args)
        {
            // Creaing a tuple object by using a helper method
            // Create an 8-tuple that contains prime numbers that are less than 20
            var primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17,19);
            Console.WriteLine($"Prime numbers less than 20:{primes.Item1},{primes.Item2}," +
                $"{primes.Item3},{primes.Item4},{primes.Item5},{primes.Item6},{primes.Item7},{primes.Rest.Item1}");


            // Creating a 7-tuple by constructor,the code to do so can be cumbersome
            //Tuple<string,int,int,int,int,int> population = new Tuple<string, int, int, int, int, int>("New York", 100, 200, 300, 400, 500);
            var population = new Tuple<string, int, int, int, int, int>("New York", 100, 200, 300, 400, 500);

            // The Create helper method directly supports the creation of tuple objects that have
            // from one to eight components


            Console.ReadKey();
        }
    }
}


參考文章

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章