
- 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 iterate over a C# tuple?
Firstly, declare a tuple and add values −
Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom");
With C#, to iterate over a tuple, you can go for individual elements −
tuple.Item1 // first item tuple.Item2 // second item To display the complete tuple, just use: // display entire tuple Console.WriteLine(tuple);
Let us see the complete code −
Example
using System; using System.Threading; namespace Demo { class Program { static void Main(string[] args) { Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom"); if (tuple.Item1 == 100) { Console.WriteLine(tuple.Item1); } if (tuple.Item2 == "Tom") { Console.WriteLine(tuple.Item2); } // display entire tuple Console.WriteLine(tuple); } } }
- Related Articles
- How to iterate over a Java list?
- How to iterate over a C# dictionary?
- How to iterate over a C# list?
- How to iterate through a tuple in Python?
- How to iterate over a Hashmap in Kotlin?
- How to iterate over a list in Java?
- How to iterate over all MongoDB databases?
- Java Program to Iterate over a HashMap
- Java Program to Iterate over a Set
- C++ Program to Iterate Over a Dictionary
- Golang program to iterate over a Slice
- How to iterate over rows in a DataFrame in Pandas?
- Iterate over a dictionary in Python
- Iterate over a list in Python
- Iterate over a set in Python

Advertisements