I have dictionary objects in my c#. but I need to migrate to typescript. I am new to typescript. I really don't know, how to use dictionary in typescript.
C#:
LengthsByCountry = new Dictionary<string, int>
{
{"AD", 24}, {"AL", 28}, {"AT", 20}, {"BA", 20},
{"BE", 16}, {"BG", 22}, {"CH", 21}, {"CY", 28},
{"CZ", 24}, {"DE", 22}, {"DK", 18}, {"EE", 20},
{"ES", 24}, {"FI", 18}, {"FO", 18}, {"FR", 27},
{"GB", 22}, {"GE", 22}, {"GI", 23}, {"GL", 18},
{"GR", 27}, {"HR", 21}, {"HU", 28}, {"IE", 22},
{"IL", 23}, {"IS", 26}, {"IT", 27}, {"LB", 28},
{"LI", 21}, {"LT", 20}, {"LU", 20}, {"LV", 21},
{"MC", 27}, {"ME", 22}, {"MK", 19}, {"MT", 31},
{"MU", 30}, {"NL", 18}, {"NO", 15}, {"PL", 28},
{"PT", 25}, {"RO", 24}, {"RS", 22}, {"SA", 24},
{"SE", 24}, {"SI", 19}, {"SK", 24}, {"SM", 27},
{"TN", 24}, {"TR", 26}
};
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C language is simple and easy to learn. C is a machine independent language, which means a C program written one machine can run on another machine without requiring a code change. C is a compiler based language and it supports only useful features which makes the compilation of C file fast.
You can do something like this:
let lengthsByCountry: { [key: string]: number; } = {};
Then initialize the items:
lengthsByCountry["AD"] = 24;
There's no direct mapping for the inline initialization at present, as far as I know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With