Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

วิธีสร้าง Tuple ว่างใน C#

ประกาศ Tuple โดยไม่กำหนดค่า:

Tuple<string, string> myTuple;

ตรวจสอบค่าใน Tuple ว่าเป็น null หรือไม่:

ตัวอย่าง

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