How to initialize a tuple to an empty tuple in C#?


To initialize a tuple to an empty tuple −

Tuple<string, string> myTuple;

If you want to check for values in a tuple, that whether it is null or not −

Example

using System;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         Tuple <int, string> tuple = new Tuple<int, string>(10, null);

         if (tuple.Item1 == 10) {
            Console.WriteLine(tuple.Item1);
         }

         if (tuple.Item2 == null) {
            Console.WriteLine("Item is null");
         }
      }
   }
}

Updated on: 22-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements