How to declare and init a static Dictionary

Date: 15 Feb 2010 Comments: 0

You may want to declare a static Dictionary variable in you code, here’s a simple example how it can be done in C#:

using System.Collections.Generic;

public static Dictionary<string, string> dict = new Dictionary<string, string>() {
{“key 1″, “value 1″},
{“key 2″, “value 2″},
{“key 3″, “value 3″}
};

That’s all. It’s similar to the array declaration :)

Leave a Reply