- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Tuple Class in C#
The Tuple<T1> class represents a 1-tuple, which is called singleton. A tuple is a data structure that has a sequence of elements.
It is used in −
- Easier access to a data set.
- Easier manipulation of a data set.
- To represent a single set of data.
- To return multiple values from a method
- To pass multiple values to a method
It has one property −
Item1 − Get the value of the current Tuple<T1> object's first component.
Example
Let us now see an example to implement the 1-tuple in C# −
using System; public class Demo { public static void Main(string[] args) { Tuple<int> tuple = new Tuple<int>(100); Console.WriteLine("Value = " + tuple.Item1); if (tuple.Item1 == 150) { Console.WriteLine(tuple.Item1); } if (tuple.Item1 == 100) { Console.WriteLine(tuple.Item1); } } }
Output
This will produce the following output −
Value = 100 100
Example
Let us now see another example to implement the 1-tuple in C# −
using System; public class Demo { public static void Main(string[] args) { Tuple<string> tuple = new Tuple<string>("amit"); Console.WriteLine("Value = " + tuple.Item1); if (tuple.Item1 == "tom") { Console.WriteLine(tuple.Item1); } if (tuple.Item1 == "amit") { Console.WriteLine("Exists: Tuple Value = " +tuple.Item1); } } }
Output
This will produce the following output −
Value = amit Exists: Tuple Value = amit
Advertisements