C# Tuple Item2
Description
Tuple Item2
gets the value of the current
Tuple object's second component.
Syntax
Tuple<T1, T2>.Item2
has the following syntax.
public T2 Item2 { get; }
Example
The example illustrates the use of the Item1 and Item2 properties to define a method that returns multiple values in the form of a 2-tuple.
using System;//from w ww . ja v a 2 s . c om
public class Class1
{
public static void Main()
{
int dividend, divisor;
Tuple<int, int> result;
dividend = 136945; divisor = 178;
try {
int remainder;
int quotient = Math.DivRem(dividend, divisor, out remainder);
result = new Tuple<int, int>(quotient, remainder);
}
catch (DivideByZeroException) {
result = null;
}
if (result != null)
Console.WriteLine(@"{0} \ {1} = {2}, remainder {3}",
dividend, divisor, result.Item1, result.Item2);
else
Console.WriteLine(@"{0} \ {1} = <Error>", dividend, divisor);
}
}
The code above generates the following result.