59.SortedList in C#
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 s1 = new SortedList();
s1.Add("key1", 50);
s1.Add("key2", 60);
s1.Add("key3", 70);
s1.Add("key4", 80);
s1.Add("key5", 90);
foreach (DictionaryEntry sname in s1)
{
Console.WriteLine("Key : " + sname.Key + " And Values : " + sname.Value);
}
Console.WriteLine("Size of Sorted List is :" + s1.Capacity);
s1.Capacity = 200;
Console.WriteLine("After Set Size of Sorted List is :" + s1.Capacity);
s1.TrimToSize();
Console.WriteLine("After Triming the Size of Sorted List is :" + s1.Capacity);
s1.Remove("key1");
Console.WriteLine("====== After Remove () Method =======");
for (int i = 0; i < s1.Count; i++)
{
Console.WriteLine(" Key = " + s1.GetKey(i) + "===> Value = " + s1.GetByIndex(i));
}
s1.RemoveAt(0);
Console.WriteLine("====== After Remove At() Method =======");
for (int i = 0; i < s1.Count; i++)
{
Console.WriteLine(" Key = " + s1.GetKey(i) + "===> Value = " + s1.GetByIndex(i));
}
Console.WriteLine("Contains Key() Result is :" + s1.ContainsKey("key3"));
Console.WriteLine("Contains Value() Result is:" + s1.ContainsValue(50));
SortedList newlist = (SortedList)s1.Clone();
Console.WriteLine("====== After Cloning The Object =============");
for (int i = 0; i < newlist.Count; i++)
{
Console.WriteLine(" Key = " + newlist.GetKey(i) + "===> Value = " + newlist.GetByIndex(i));
}
ArrayList myarraylist = new ArrayList();
myarraylist = ArrayList.Adapter(s1.GetKeyList());
Console.WriteLine("====== After Convert Sorted List into Array List ========");
for (int i = 0; i < myarraylist.Count; i++)
{
Console.WriteLine("Array List Key is :" + myarraylist[i]);
}
ArrayList arr1 = new ArrayList();
arr1 = ArrayList.Adapter(s1.GetValueList());
Console.WriteLine("===== After Convert Sorted List into Array List =======");
for (int i = 0; i < arr1.Count; i++)
{
Console.WriteLine("Array List Value is :" + arr1[i]);
}
Console.Read();
}
}
}
Comments
Post a Comment