ด้วย C# คุณสามารถตั้งค่าทูเพิล 6 รายการได้อย่างง่ายดาย
ต่อไปนี้เป็นทูเพิล 6 รายการ -
var myTuple = new Tuple<string, string[], int, int, int, int>("electronics",
new string[] { "shoes", "clothing#", "accessories" },
100,
250,
500,
1000); ด้านบน เรามี tuple สำหรับ string, string array และ int ดังที่แสดงด้านล่าง -
Tuple<string, string[], int, int, int, int>
นี่คือรหัสที่สมบูรณ์ -
ตัวอย่าง
using System;
class Demo {
static void Main() {
var myTuple = new Tuple<string, string[], int, int, int, int>("electronics",
new string[] { "shoes", "clothing#", "accessories" },
100,
250,
500,
1000);
// Displaying Item 1
Console.WriteLine(myTuple.Item1);
// Displaying Item 5
Console.WriteLine(myTuple.Item5);
// Displaying Item 6
Console.WriteLine(myTuple.Item6);
}
} ผลลัพธ์
electronics 500 1000