public static Dictionary<string, double> m_BankBalance = new Dictionary<string, double>();
what does this syntax mean?
Printable View
public static Dictionary<string, double> m_BankBalance = new Dictionary<string, double>();
what does this syntax mean?
The above declares and instantiates a dictionary object with string keys and double values, named m_BankBalance.
The Dictionary class uses generics, meaning that you can provide any types between < >. The first type represents the keys and the second the values. A Dictionary behaves like a hash table, having O(n) = 1 to lookup entries (values), meaning it has the fastest item lookup. Keys must be unique, so you can't add two values with the same key.
The first part is the declaration:
The second part is the instantiation, which can also be done in code (in fact, the compiler will move the statement inside the constructor). To instantiate a new Dictionary object, the following statement is used:Code:public static Dictionary<string, double> m_BankBalance
This is a call to the default constructor (which takes no parameters), but the generic types have to be specified.Code:m_BankBalance = new Dictionary<string, double>();