- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Getting the value at the specified index of a SortedList object in C#
To get the value at the specified index 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", "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"); Console.WriteLine("Value at index 2 = "+list.GetByIndex(2)); Console.WriteLine("Value at index 5 = "+list.GetByIndex(5)); Console.WriteLine("Value at index 6 = "+list.GetByIndex(6)); } }
Output
This will produce the following output −
Value at index 2 = Tom Value at index 5 = Mark Value at index 6 = Gary
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(1, "One"); list.Add(2, "Two"); list.Add(3, "Three"); list.Add(4, "Four"); list.Add(5, "Five"); Console.WriteLine("Value at index 0 = "+list.GetByIndex(0)); } }
Output
This will produce the following output −
Value at index 0 = One
Advertisements