CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Posts
    1

    couldn't understand syntax

    public static Dictionary<string, double> m_BankBalance = new Dictionary<string, double>();

    what does this syntax mean?

  2. #2
    Join Date
    Oct 2006
    Location
    Timisoara, Romania
    Posts
    123

    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
  •  





Click Here to Expand Forum to Full Width

Featured