Home >Backend Development >C#.Net Tutorial >How to initialize a tuple to an empty tuple in C#?

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

PHPz
PHPzforward
2023-09-03 19:37:02936browse

如何在 C# 中将元组初始化为空元组?

Initialize the tuple to an empty tuple -

Tuple<string, string> myTuple;

If you want to check the value in the tuple i.e. if it is null -

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");
         }
      }
   }
}

The above is the detailed content of How to initialize a tuple to an empty tuple in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Assertions in C#Next article:Assertions in C#