Freek's Blog

SQL en .NET vraagstukken en oplossingen die ik zoal tegenkom
posts - 199, comments - 123, trackbacks - 2, articles - 7

My Links

News

Google analytics script: Locations of visitors to this page

Article Categories

Archives

Post Categories

Image Galleries

Algemene links

MSDN

vb links

C#: using the sortedlist

Posted on Monday, May 10, 2010 5:01 PM

 

 

System.Collections.Generic.SortedDictionary<string, long> Dic = new SortedDictionary<string, long>();

.
..
...
....
...
..
.

 

Collect some key's and there values



//contains list already the key value (here represented by: ext)?
if (Dic.Keys.Contains(ext))
{
//found in list then add 1 to the value.
long i = Dic[ext]; // get the value for the key
i++;//add 1
Dic[ext] = i;//update value
}
else
{
//not? then add this key and set default value to 1.
Dic.Add(ext, 1);
}

.
..
...
....
...
..
.

Read out the sortedlist

 

//print dictionary e.g. to screen

foreach (var pair in Dic)
{
this.textBox1.AppendText(pair.ToString() + "\r\n");
Application.DoEvents();
}

//remove all entries
Dic.Clear();

 

Output will be like

[the key, the value]
[the key, the value]
[the key, the value]
[the key, the value]
etc, etc..

 

 

 

 

Post Comment

Title  
Name  
Url
Comment   

ATTENTION: the code you need to copy is CaSe SeNsItIvE and is required to prevent spam.
Enter the code you see: