如何在 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 千+ 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始學習
廣告