C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






SortedList basics


Posted Date: 20 Jun 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Kapil DhawanMember Level: Gold    
Rating: Points: 5



SortedList is a part of System.Collection class. It works the same way Hashtable does. That is it takes KEY-VALUE pairs as input.

An advantage of SortedList is that it gives the output sorted by KEY values.
For example


SortedList oSL = new SortedList();
oSL.Add("A", "1");
oSL.Add("C", "2");
oSL.Add("E", "3");
oSL.Add("B", "4");
oSL.Add("D", "5");
oSL.Add("F", "6");

IDictionaryEnumerator oIDic = oSL.GetEnumerator();
while (oIDic.MoveNext())
{
Response.Write(oIDic.Value.ToString());
Response.Write("
");
}


Output will be:


1
4
2
5
3
6



To remove a value from the list we use


oSL.Remove("D");






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
SortedList example  .  SortedList code sample  .  Example for SortedList  .  Basics of SortedList  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Use of Interface
Previous Resource: Use of Switch Case Statements
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use