Click here to Skip to main content
15,922,533 members
Home / Discussions / C#
   

C#

 
GeneralRe: Multiple Icons in Icon File Pin
redfish3421-May-06 12:08
redfish3421-May-06 12:08 
Questionhow to protect usb disc by password ? Pin
Veelone10-May-06 16:56
Veelone10-May-06 16:56 
QuestionIs there any Win32 API can change windows logon password? Pin
Veelone10-May-06 16:55
Veelone10-May-06 16:55 
Questionhow to disable usb disk Pin
Veelone10-May-06 16:53
Veelone10-May-06 16:53 
AnswerRe: how to disable usb disk Pin
alexey N10-May-06 17:36
alexey N10-May-06 17:36 
QuestionText file Sorting. Pin
jrbvillanueva10-May-06 16:36
jrbvillanueva10-May-06 16:36 
QuestionRe: Text file Sorting. Pin
DigitalKing10-May-06 20:23
DigitalKing10-May-06 20:23 
AnswerRe: Text file Sorting. Pin
Guffa10-May-06 21:32
Guffa10-May-06 21:32 
Here is an example from MSDN on how to use a SortedList object:

using System;
using System.Collections.Generic;

public class Example
{
	public static void Main()
	{
		// Create a new sorted list of strings, with string
		// keys.
		SortedList<string, string> openWith = 
			new SortedList<string, string>();

		// Add some elements to the list. There are no 
		// duplicate keys, but some of the values are duplicates.
		openWith.Add("txt", "notepad.exe");
		openWith.Add("bmp", "paint.exe");
		openWith.Add("dib", "paint.exe");
		openWith.Add("rtf", "wordpad.exe");

		// The Add method throws an exception if the new key is 
		// already in the list.
		try
		{
			openWith.Add("txt", "winword.exe");
		}
		catch (ArgumentException)
		{
			Console.WriteLine("An element with Key = \"txt\" already exists.");
		}

		// The Item property is another name for the indexer, so you 
		// can omit its name when accessing elements. 
		Console.WriteLine("For key = \"rtf\", value = {0}.", 
			openWith["rtf"]);

		// The indexer can be used to change the value associated
		// with a key.
		openWith["rtf"] = "winword.exe";
		Console.WriteLine("For key = \"rtf\", value = {0}.", 
			openWith["rtf"]);

		// If a key does not exist, setting the indexer for that key
		// adds a new key/value pair.
		openWith["doc"] = "winword.exe";

		// The indexer throws an exception if the requested key is
		// not in the list.
		try
		{
			Console.WriteLine("For key = \"tif\", value = {0}.", 
				openWith["tif"]);
		}
		catch (KeyNotFoundException)
		{
			Console.WriteLine("Key = \"tif\" is not found.");
		}

		// When a program often has to try keys that turn out not to
		// be in the list, TryGetValue can be a more efficient 
		// way to retrieve values.
		string value = "";
		if (openWith.TryGetValue("tif", out value))
		{
			Console.WriteLine("For key = \"tif\", value = {0}.", value);
		}
		else
		{
			Console.WriteLine("Key = \"tif\" is not found.");
		}

		// ContainsKey can be used to test keys before inserting 
		// them.
		if (!openWith.ContainsKey("ht"))
		{
			openWith.Add("ht", "hypertrm.exe");
			Console.WriteLine("Value added for key = \"ht\": {0}", 
				openWith["ht"]);
		}

		// When you use foreach to enumerate list elements,
		// the elements are retrieved as KeyValuePair objects.
		Console.WriteLine();
		foreach( KeyValuePair<string, string> kvp in openWith )
		{
			Console.WriteLine("Key = {0}, Value = {1}", 
				kvp.Key, kvp.Value);
		}

		// To get the values alone, use the Values property.
		IList<string> ilistValues = openWith.Values;

		// The elements of the list are strongly typed with the 
		// type that was specified for the SorteList values.
		Console.WriteLine();
		foreach( string s in ilistValues )
		{
			Console.WriteLine("Value = {0}", s);
		}

		// The Values property is an efficient way to retrieve
		// values by index.
		Console.WriteLine("\nIndexed retrieval using the Values " +
			"property: Values[2] = {0}", openWith.Values[2]);

		// To get the keys alone, use the Keys property.
		IList<string> ilistKeys = openWith.Keys;

		// The elements of the list are strongly typed with the 
		// type that was specified for the SortedList keys.
		Console.WriteLine();
		foreach( string s in ilistKeys )
		{
			Console.WriteLine("Key = {0}", s);
		}

		// The Keys property is an efficient way to retrieve
		// keys by index.
		Console.WriteLine("\nIndexed retrieval using the Keys " +
			"property: Keys[2] = {0}", openWith.Keys[2]);

		// Use the Remove method to remove a key/value pair.
		Console.WriteLine("\nRemove(\"doc\")");
		openWith.Remove("doc");

		if (!openWith.ContainsKey("doc"))
		{
			Console.WriteLine("Key \"doc\" is not found.");
		}
	}
}

/* This code example produces the following output:

An element with Key = "txt" already exists.
For key = "rtf", value = wordpad.exe.
For key = "rtf", value = winword.exe.
Key = "tif" is not found.
Key = "tif" is not found.
Value added for key = "ht": hypertrm.exe

Key = bmp, Value = paint.exe
Key = dib, Value = paint.exe
Key = doc, Value = winword.exe
Key = ht, Value = hypertrm.exe
Key = rtf, Value = winword.exe
Key = txt, Value = notepad.exe

Value = paint.exe
Value = paint.exe
Value = winword.exe
Value = hypertrm.exe
Value = winword.exe
Value = notepad.exe

Indexed retrieval using the Values property: Values[2] = winword.exe

Key = bmp
Key = dib
Key = doc
Key = ht
Key = rtf
Key = txt

Indexed retrieval using the Keys property: Keys[2] = doc

Remove("doc")
Key "doc" is not found.
*/


---
b { font-weight: normal; }

AnswerRe: Text file Sorting. Pin
esjq10-May-06 20:55
esjq10-May-06 20:55 
GeneralRe: Text file Sorting. Pin
jrbvillanueva10-May-06 21:06
jrbvillanueva10-May-06 21:06 
Question.NET Remoting hosted on IIS - suddenly getting SerializationException Pin
Luis Alonso Ramos10-May-06 15:33
Luis Alonso Ramos10-May-06 15:33 
AnswerFixed! Pin
Luis Alonso Ramos10-May-06 17:07
Luis Alonso Ramos10-May-06 17:07 
QuestionUser Instance Headache : SQL Server 2005 Express Pin
emran83410-May-06 12:12
emran83410-May-06 12:12 
AnswerRe: User Instance Headache : SQL Server 2005 Express Pin
Chemisus10-May-06 18:18
Chemisus10-May-06 18:18 
QuestionHow to get menubar in Grey Color using C#? Pin
irumamir10-May-06 12:09
irumamir10-May-06 12:09 
AnswerRe: How to get menubar in Grey Color using C#? Pin
Paul Conrad10-May-06 15:38
professionalPaul Conrad10-May-06 15:38 
GeneralRe: How to get menubar in Grey Color using C#? Pin
irumamir10-May-06 15:44
irumamir10-May-06 15:44 
GeneralRe: How to get menubar in Grey Color using C#? Pin
Paul Conrad10-May-06 17:14
professionalPaul Conrad10-May-06 17:14 
GeneralRe: How to get menubar in Grey Color using C#? Pin
irumamir10-May-06 18:21
irumamir10-May-06 18:21 
GeneralRe: How to get menubar in Grey Color using C#? Pin
Paul Conrad10-May-06 19:29
professionalPaul Conrad10-May-06 19:29 
QuestionAutomated login Pin
indimu10-May-06 10:38
indimu10-May-06 10:38 
Questionhow add a [property] as dialogbox Pin
Susuko10-May-06 10:36
Susuko10-May-06 10:36 
AnswerRe: how add a [property] as dialogbox Pin
Office Lineman10-May-06 11:48
Office Lineman10-May-06 11:48 
GeneralRe: how add a [property] as dialogbox Pin
Susuko12-May-06 11:38
Susuko12-May-06 11:38 
Questionagain:Speech sdk 5.1 Pin
TheEagle10-May-06 10:03
TheEagle10-May-06 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.