Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

C# में SortedList ऑब्जेक्ट के मानों की सूची प्राप्त करें

SortedList.GetValueList() मेथड कुंजियों के क्रम के अनुसार क्रमबद्ध मानों की एक IList लौटाता है। लौटाई गई सूची सॉर्टेडलिस्ट से जुड़ी होती है - सॉर्टेडलिस्ट में परिवर्तन सूची में दिखाई देते हैं।

उदाहरण 1: पूर्णांक मानों के साथ

using System;
using System.Collections;

public class Demo
{
    public static void Main(String[] args)
    {
        SortedList list = new SortedList();
        list.Add("A", 1);
        list.Add("B ", 2);
        list.Add("C ", 3);
        list.Add("D", 4);
        list.Add("E", 5);
        list.Add("F", 6);
        list.Add("G", 7);
        list.Add("H", 8);
        Console.WriteLine("SortedList elements...");
        foreach (DictionaryEntry d in list)
        {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("\nList of values...SortedList");
        IList col = list.GetValueList();
        foreach (int res in col)
            Console.WriteLine(res);
    }
}

आउटपुट

SortedList elements...
A 1
B  2
C  3
D 4
E 5
F 6
G 7
H 8
List of values...SortedList
1
2
3
4
5
6
7
8

उदाहरण 2: स्ट्रिंग मानों के साथ

using System;
using System.Collections;

public class Demo
{
    public static void Main(String[] args)
    {
        SortedList list = new SortedList();
        list.Add("One", "IT");
        list.Add("Two ", "Operations");
        list.Add("Three", "Marketing");
        list.Add("Four", "Purchase");
        list.Add("Five", "Sales");
        list.Add("Six", "Finance");
        Console.WriteLine("SortedList elements...");
        foreach (DictionaryEntry d in list)
        {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("\nList of values...SortedList");
        IList col = list.GetValueList();
        foreach (string res in col)
            Console.WriteLine(res);
    }
}

आउटपुट

SortedList elements...
Five Sales
Four Purchase
One IT
Six Finance
Three Marketing
Two  Operations
List of values...SortedList
Sales
Purchase
IT
Finance
Marketing
Operations

नोट: कुंजियों में अनुगामी स्पेस ("B ", "C ", "Two ") क्रम को प्रभावित करते हैं। GetValueList स्नैपशॉट नहीं बल्कि लाइव दृश्य लौटाता है। आधुनिक कोड में SortedDictionary<TKey, TValue>.Values पसंद किया जाता है।

  1. - C# लिस्ट में इंटीजर वैल्यूज़ कैसे जोड़ें?

    C# में लिस्ट में इंटीजर वैल्यूज़ जोड़ने के लिए, Add() मेथड का उपयोग करें।सबसे पहले, C# में एक इंटीजर लिस्ट घोषित करें:List list1 = new List();अब इंटीजर वैल्यूज़ जोड़ें:list1.Add(900); list1.Add(400); list1.Add(300);आइए पूरा कोड देखें:उदाहरणusing System; using System.Collections.Generic; using System

  1. - C# में SortedList क्लास क्या है?

    एक सॉर्टेड लिस्ट एक ऐरे और हैश टेबल का संयोजन है। इसमें आइटम्स की एक सूची होती है जिसे की या इंडेक्स का उपयोग करके एक्सेस किया जा सकता है। यदि आप इंडेक्स का उपयोग करके आइटम्स एक्सेस करते हैं, तो यह एक ArrayList है, और यदि आप की का उपयोग करके आइटम्स एक्सेस करते हैं, तो यह एक Hashtable है। आइटम्स का स

  1. - C# में SortedList क्लास की Values प्रॉपर्टी क्या है

    सबसे पहले, SortedList क्लास डिक्लेयर करें - SortedList list = new SortedList(); अब वैल्यूज़ जोड़ें - list.Add(S1, Wallets); list.Add(S2, Sunglasses); list.Add(S3, Backpacks); SortedList क्लास की Values प्रॉपर्टी के साथ काम करने का कोड निम्नलिखित है - उदाहरण using System; using System.Collections; na