KeyValuePair<TKey, TValue> একটি কী-ভ্যালু জোড়া সংরক্ষণ করে। এটি ডিকশনারির সব এন্ট্রি এই টাইপের। লিস্টে একাধিক জোড়া রাখতে এটি ব্যবহার করা হয়।
উদাহরণ
using System;
using System.Collections.Generic;
class Program {
static void Main() {
var list = new List>();
list.Add(new KeyValuePair("Laptop", 20));
list.Add(new KeyValuePair("Desktop", 40));
list.Add(new KeyValuePair("Tablet", 60));
foreach (var item in list) {
Console.WriteLine($"Key: {item.Key}, Value: {item.Value}");
}
}
}
আউটপুট
Key: Laptop, Value: 20 Key: Desktop, Value: 40 Key: Tablet, Value: 60