What does this expression a [b] mean in C #

I often saw this expression in the service code

Global["Name"]

What does this mean? I used Global.Name, but never Global["Name"]?

Is there a place where this type of expression is used?

+3
source share
3 answers

It is used when searching dictionaries and collections containing key / value pairs, for example.

var peopleAges = new System.Collections.Generic.Dictionary<string, int>();
peopleAges["fred"] = 21;
peopleAges["emma"] = 18;

var fredAge = peopleAges["fred"];  // returns 21
+3
source

This is called an indexer . In this case Global, it is probably some kind of dictionary or hash table. "Name"is the key to access a specific item in this dictionary

+8
source

, #, default. DefaultMemberAttribute, #, , , .

0

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


All Articles