
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Getting the list of Values of a SortedList object in C#
To get the list of values of a SortedList object, the code is as follows −
Example
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("
List of values...SortedList"); IList col = list.GetValueList(); foreach(int res in col) Console.WriteLine(res); } }
Output
This will produce the following output −
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
Example
Let us see another example −
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("
List of values...SortedList"); IList col = list.GetValueList(); foreach(string res in col) Console.WriteLine(res); } }
Output
This will produce the following output −
SortedList elements... Five Sales Four Purchase One IT Six Finance Three Marketing Two Operations List of values...SortedList Sales Purchase IT Finance Marketing Operations
- Related Articles
- Getting the list of keys of a SortedList object in C#
- Getting the Values in a SortedList object in C#
- Getting the keys in a SortedList object C#
- Getting index of the specified value in a SortedList object in C#
- Getting the index of the specified key in a SortedList object in C#
- Getting the key at the specified index of a SortedList object in C#
- Getting the value at the specified index of a SortedList object in C#
- Search in a SortedList object in C#
- What is the Values property of SortedList class in C#?
- Getting a list of values by using MongoDB $group?
- How to create a shallow copy of SortedList Object in C#?
- Setting the capacity to the actual number of elements in a SortedList object in C#?
- Check if a SortedList object is synchronized in C#
- Capacity of a SortedList in C#
- Creating a synchronized wrapper for a SortedList object in C#

Advertisements