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


要将元组初始化为空元组 -

Tuple<string, string> myTuple;

如果你想在元组中检查值,即它是否为空 -

示例

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

更新于: 22-6 月-2020

2 千+ 次浏览

开启你的 职业生涯

完成课程即可获得认证

开始学习
广告
© . All rights reserved.