
- 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
Getting the Type of the Tuple’s Element in C#
To get the type of the Tuple’s element, the code is as follows −
Example
using System; public class Demo { public static void Main(String[] args){ var tuple1 = Tuple.Create(150, 1500, Tuple.Create(50, 100)); var tuple2 = Tuple.Create(150, 1500, Tuple.Create(100, 200)); Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode()); Console.WriteLine("Type of Tuple1 = "+tuple1.GetType()); Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode()); Console.WriteLine("Type of Tuple1 = "+tuple2.GetType()); } }
Output
This will produce the following output −
Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = 188892 Type of Tuple1 = System.Tuple`3[System.Int32,System.Int32,System.Tuple`2[System.Int32,System.Int32]] HashCode of Tuple2 = 191462 Type of Tuple1 = System.Tuple`3[System.Int32,System.Int32,System.Tuple`2[System.Int32,System.Int32]]
Example
Let us now see another example −
using System; public class Demo { public static void Main(String[] args){ var tuple1 = Tuple.Create(10, 20); var tuple2 = Tuple.Create(30, 40); Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode()); Console.WriteLine("Type of Tuple1 = "+tuple1.GetType()); Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode()); Console.WriteLine("Type of Tuple1 = "+tuple2.GetType()); } }
Output
This will produce the following output −
Is Tuple1 equal to Tuple2? = False HashCode of Tuple1 = 350 Type of Tuple1 = System.Tuple`2[System.Int32,System.Int32] HashCode of Tuple2 = 1014 Type of Tuple1 = System.Tuple`2[System.Int32,System.Int32]
- Related Articles
- Getting the type of the current instance in C#
- Use of the DFN element type in HTML
- What is the use of the ADDRESS element type in HTML?
- What is the use of the VAR element type in HTML?
- How do we set the type of element in HTML?
- Getting the list of keys of a SortedList object in C#
- Getting the list of Values of a SortedList object in C#
- Get the underlying type of the current enumeration type C#
- Getting the Largest Window Height and Width of the Console in C#
- Getting the index of the specified key in a SortedList object in C#
- Getting the keys in a SortedList object C#
- Get the fields of the current Type in C#
- Get the members of the current Type in C#
- Python Getting sublist element till N
- Getting the Values in a SortedList object in C#

Advertisements