
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to create 2-tuple or pair tuple in C#?
The Tuple<T1, T2> class represents a 2-tuple, which is called pair. A tuple is a data structure that has a sequence of elements.
Example
Let us now see an example to implement the 2-tuple in C# −
using System; public class Demo { public static void Main(string[] args) { Tuple<string,string> tuple = new Tuple<string,string>("jack", "steve"); Console.WriteLine("Value = " + tuple.Item1); if (tuple.Item1 == "jack") { Console.WriteLine("Exists: Tuple Value = " +tuple.Item1); } if (tuple.Item2 == "david") { Console.WriteLine("Exists: Tuple Value = " +tuple.Item2); } } }
Output
This will produce the following output −
Value = jack Exists: Tuple Value = jack
Example
Let us now see another example to implement the 2-tuple in C# −
using System; public class Demo { public static void Main(string[] args) { Tuple tuple = new Tuple(20, "steve"); Console.WriteLine("Value = " + tuple.Item1); if (tuple.Item1 == 20) { Console.WriteLine("Exists: Tuple Value = " +tuple.Item1); } if (tuple.Item2 == "david") { Console.WriteLine("Exists: Tuple Value = " +tuple.Item2); } } }
Output
This will produce the following output −
Value = 20 Exists: Tuple Value = 20
- Related Articles
- Create Pair Tuple in Java
- How to create 3-Tuple or Triple Tuple in C#?
- How to create 1-Tuple or Singleton Tuple in C#?
- Create Pair Tuple from List in Java
- Create Pair Tuple from Array in Java
- Create Pair Tuple using with() method in Java
- Create Pair Tuple from another collection in Java
- How to create 4-Tuple or quadruple in C#?
- How to create 5-Tuple or quintuple in C#?
- How to create 7-Tuple or Septuple in C#?
- How to create LabelValue Tuple in Java?
- How to create Decade Tuple in Java?
- How to create Ennead Tuple in Java?
- How to create KeyValue Tuple in Java?
- How to create Octet Tuple in Java?

Advertisements