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 !




The Keys and Values Collections in C#


Posted Date: 09 Jun 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: VijayKumar Reddy MMember Level: Gold    
Rating: Points: 10



Dictionary collections provide two additional properties: Keys and Values. Keys retrieves an
ICollection object with all the keys in the Hashtable, as Values retrieves an ICollection
object with all the values.


using System.Collections;


// Create and initialize a new Hashtable.
Hashtable hashTable = new Hashtable( );
hashTable.Add("1", "AndhraPradesh");
hashTable.Add("2", "TamilNadu");
hashTable.Add("3", "Karnataka");
hashTable.Add("4", "Punjab");
// get the keys from the hashTable
ICollection keys = hashTable.Keys;
// get the values
ICollection values = hashTable.Values;
// iterate over the keys ICollection
foreach(string key in keys)
{
Console.WriteLine("{0} ", key);
}
// iterate over the values collection
foreach (string val in values)
{
Console.WriteLine("{0} ", val);
}


OutPut:
1
2
3
4
AndhraPradesh
TamilNadu
Karnataka
Punjab




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: Image Procsessing C# windows (Writing string on Image)
Previous Resource: How to do Connection Pooling Performance Improvement:
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