Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to create 1-Tuple or Singleton Tuple in C#?
The Tuple
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 tuple = new Tuple(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 tuple = new Tuple("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
