Represent a 2-tuple, or pair in CSharp

Description

The following code shows how to represent a 2-tuple, or pair.

Example


//from   w w  w .ja va 2 s.c o  m
  
  
  

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

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var