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…

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: