C#-এ আলাদা Pair ক্লাস নেই; KeyValuePair<TKey, TValue> একটি জোড়া মান সংরক্ষণ করে। লিস্টে একাধিক জোড়া রাখতে এটি ব্যবহার করা হয়।
উদাহরণ
using System;
using System.Collections.Generic;
class Program {
static void Main() {
var list = new List>();
list.Add(new KeyValuePair("Laptop", 1));
list.Add(new KeyValuePair("Desktop", 2));
list.Add(new KeyValuePair("Tablet", 3));
list.Add(new KeyValuePair("Mobile", 4));
list.Add(new KeyValuePair("E-Book", 5));
list.Add(new KeyValuePair("LED", 6));
foreach (var kvp in list) {
Console.WriteLine($"[{kvp.Key}, {kvp.Value}]");
}
}
}
আউটপুট
[Laptop, 1] [Desktop, 2] [Tablet, 3] [Mobile, 4] [E-Book, 5] [LED, 6]