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

PHPz
Release: 2023-09-03 19:37:02
forward
932 people have browsed it

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

Initialize the tuple to an empty tuple -

Tuple<string, string> myTuple;
Copy after login

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template