सबसे पहले, एक टपल घोषित करें और मान जोड़ें -
Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom");
C# के साथ, टपल पर पुनरावृति करने के लिए, आप अलग-अलग तत्वों के लिए जा सकते हैं -
tuple.Item1 // first item tuple.Item2 // second item To display the complete tuple, just use: // display entire tuple Console.WriteLine(tuple);
आइए देखें पूरा कोड -
उदाहरण
using System;
using System.Threading;
namespace Demo {
class Program {
static void Main(string[] args) {
Tuple <int, string> tuple = new Tuple<int, string>(100, "Tom");
if (tuple.Item1 == 100) {
Console.WriteLine(tuple.Item1);
}
if (tuple.Item2 == "Tom") {
Console.WriteLine(tuple.Item2);
}
// display entire tuple
Console.WriteLine(tuple);
}
}
}