Tuple(T1, T2) Represents a 2-tuple, or pair. : Tuple « Data Types « C# / C Sharp






Tuple(T1, T2) Represents a 2-tuple, or pair.

 

using System;

public class Example
{
    public static void Main()
    {
        Tuple<string, Nullable<int>>[] scores = 
                    { new Tuple<string, Nullable<int>>("A", 78),
                      new Tuple<string, Nullable<int>>("B", 84) };
        output(scores);
    }

    private static void output(Tuple<string, Nullable<int>>[] scores)
    {
        foreach (var score in scores)
        {
            if (score.Item2.HasValue)
            {
                Console.WriteLine(score.Item2.Value);
            }
        }
    }
}

   
  








Related examples in the same category

1.Tuple Class Provides static methods for creating tuple objects.
2.Use Tuple to get more than one value from a method