কম্পিউটার টিউটোরিয়াল

C#-এ Pair ক্লাস (KeyValuePair)

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]
  1. C# Console ক্লাস

  2. C#-এ KeyValuePair ক্লাস

  3. C#-এ সিঙ্গলটন প্যাটার্ন ইমপ্লিমেন্টেশন

  4. C#-এ ক্লাস (Class in C#)