![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
How to declare a tuple in C#?
To declare a tuple the following is the format wherein we have a tuple with int and string items −
Tuple<int, string> tuple = new Tuple<int, string>(20, "Tom");
Now, check for first item in the tuple, which is an integer −
if (tuple.Item1 == 99) { Console.WriteLine(tuple.Item1); }
Now check for second item in the tuple, which is a string −
if (tuple.Item2 == "Tim") { Console.WriteLine(tuple.Item2); }
The following is an example to create a tuple with string and int items −
using System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { Tuple<int, string> tuple = new Tuple<int, string>(50, "Tom"); if (tuple.Item1 == 99) { Console.WriteLine(tuple.Item1); } if (tuple.Item2 == "Tim") { Console.WriteLine(tuple.Item2); } } } }
Advertisements