Tuple<T1, T2>.Item1 Property
Gets the value of the current Tuple<T1, T2> object's first component.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
You can dynamically determine the type of the Item1 component in one of two ways:
By calling the GetType method on the value that is returned by the Item1 property.
By retrieving the Type object that represents the Tuple<T1, T2> object, and retrieving the first element from the array that is returned by its Type.GetGenericArguments method.
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; public class Class1 { public static void Main() { int dividend, divisor; Tuple<int, int> result; dividend = 136945; divisor = 178; result = IntegerDivide(dividend, divisor); if (result != null) Console.WriteLine(@"{0} \ {1} = {2}, remainder {3}", dividend, divisor, result.Item1, result.Item2); else Console.WriteLine(@"{0} \ {1} = <Error>", dividend, divisor); dividend = Int32.MaxValue; divisor = -2073; result = IntegerDivide(dividend, divisor); if (result != null) Console.WriteLine(@"{0} \ {1} = {2}, remainder {3}", dividend, divisor, result.Item1, result.Item2); else Console.WriteLine(@"{0} \ {1} = <Error>", dividend, divisor); } private static Tuple<int, int> IntegerDivide(int dividend, int divisor) { try { int remainder; int quotient = Math.DivRem(dividend, divisor, out remainder); return new Tuple<int, int>(quotient, remainder); } catch (DivideByZeroException) { return null; } } } // The example displays the following output: // 136945 \ 178 = 769, remainder 63 // 2147483647 \ -2073 = -1035930, remainder 757
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.