|
-
February 28th, 2008, 01:09 AM
#1
couldn't understand syntax
public static Dictionary<string, double> m_BankBalance = new Dictionary<string, double>();
what does this syntax mean?
-
February 28th, 2008, 02:29 AM
#2
Re: couldn't understand syntax
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:
Code:
public static Dictionary<string, double> m_BankBalance
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:
m_BankBalance = new Dictionary<string, double>();
This is a call to the default constructor (which takes no parameters), but the generic types have to be specified.
Last edited by riscutiavlad; February 28th, 2008 at 04:00 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|