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

CsharpProgrammingServer Side Programming

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");
         }
      }
   }
}
raja
Published on 31-Aug-2018 12:17:00
Advertisements