Initialize Dictionary in .Net 2.0

Is there an easy way to initialize a dictionary, which is a property, like in .NET 3.5 , or do I need to add elements to the class constructor?

My goal is to have a static map mapping code into a string representation.

+3
source share
3 answers

Yes, you need to initialize the constructor Dictionaryin the class.

+4
source

If your class is static, you can do it in a static constructor.

static myclass()
{
    //Do stuff here?!
}

If not, do this in your instance constructor?

+1
source

Collection Initializer .NET 3.5 .

FTA:

( ) # 3.0 , Visual Studio 2008 .NET 3.5 . .

However, you are not limited to adding elements to your class constructor. You can add this at any time, you simply cannot do this using collection initialization.

+1
source

Source: https://habr.com/ru/post/1724496/


All Articles