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

SortedList অবজেক্টে ভ্যালুগুলো পান C#-এ

SortedList অবজেক্টে ভ্যালুগুলো পেতে নিচের কোডটি ব্যবহার করা হয়:

উদাহরণ ১

using System; 
using System.Collections; 
public class Demo { 
    public static void Main(String[] args) { 
        SortedList list = new SortedList(); 
        list.Add(1, "One"); 
        list.Add(2, "Two"); 
        list.Add(3, "Three"); 
        list.Add(4, "Four"); 
        list.Add(5, "Five"); 
        ICollection col1 = list.Values; 
        Console.WriteLine("ভ্যালু..."); 
        foreach(string s in col1) 
            Console.WriteLine(s); 
        ICollection col2 = list.Keys; 
        Console.WriteLine("কী..."); 
        foreach(int s in col2) 
            Console.WriteLine(s); 
    } 
}

আউটপুট

এটি নিচের আউটপুটটি তৈরি করবে:

ভ্যালু... One Two Three Four Five কী... 1 2 3 4 5

উদাহরণ ২

আরেকটি উদাহরণ দেখি:

using System; 
using System.Collections; 
public class Demo { 
    public static void Main(String[] args) { 
        SortedList list = new SortedList(); 
        list.Add("A", "Jacob"); 
        list.Add("B", "Sam"); 
        list.Add("C", "Tom"); 
        list.Add("D", "John"); 
        list.Add("E", "Tim"); 
        list.Add("F", "Mark"); 
        list.Add("G", "Gary"); 
        list.Add("H", "Nathan"); 
        list.Add("I", "Shaun"); 
        list.Add("J", "David"); 
        ICollection col1 = list.Values; 
        Console.WriteLine("ভ্যালু..."); 
        foreach(string s in col1) 
            Console.WriteLine(s); 
        ICollection col2 = list.Keys; 
        Console.WriteLine("\nকী..."); 
        foreach(string s in col2) 
            Console.WriteLine(s); 
    } 
}

আউটপুট

এটি নিচের আউটপুটটি তৈরি করবে:

ভ্যালু... Jacob Sam Tom John Tim Mark Gary Nathan Shaun David কী... A B C D E F G H I J
  1. C#-এ লিস্টে স্ট্রিং ভ্যালু যোগ করা (Add String Values to List)

  2. C#-এ লিস্টে ইন্টিজার ভ্যালু যোগ করা (Add Integer Values to List)

  3. C#-এ SortedList ক্লাস (SortedList Class)

  4. C#-এ SortedList ক্লাসের Values প্রোপার্টি