Home > Development > Tuples C#

Tuples C#


Provide a way to group data items together. For example you may want a data item with a persons id and name.
A tuple provides a convenient way to do so. It is also benefical over anonymous types if you need to use it outside the current function scope.

Se the following example.

using System;

namespace Tuples
{
    class Program
    {
        static void Main(string[] args)
        {
            Tuple<int, string> t1 = new Tuple<int, string>(1,"Blair Davidson");
            Tuple<int, String> t2 = Tuple.Create(2, "Chia Ling");

            Console.WriteLine(t1.Item1 + " " + t1.Item2);

        }
    }
}

Blair…

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment