Sortedlist:
The SortedList class represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.
A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable. The collection of items is always sorted by the key value.
Code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- namespace sortedList
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedList sl = new SortedList();
- sl.Add(1,"Shimul Hossain");
- sl.Add(3,"Sujan Hasan");
- sl.Add(2,"Shakil Sorker");
- print(sl);
- sl.Remove(2);
- print(sl);
- Console.ReadKey();
- }
- public static void print(SortedList slist)
- {
- foreach (var i in slist.Keys)
- {
- Console.WriteLine(i+" : "+slist[i]);
- }
- }
- }
- }
0 Comments:
Post a Comment