Results 1 to 1 of 1

Thread: Dictionary

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User 's Avatar
    Join Date: Feb:2006
    Location:
    Posts: 653

    Cool Dictionary

    , , int string, string[]:
    1.
    debug , , ContainsKey .

    , , IEqualityComparer:
    2.
    debug , Equals . ( .)

    Equals :
    Code:
    d1.Keys.Contains<string[]>(new string[] { "a", "a" }, new StringArrayComparer())
    d1[new string[] { "a", "a" }], .

    .

    EDIT
    :
    Code:
    public int GetHashCode(string[] obj)
    {
        return 0;
    }

    , , , .
    , ContainsKey - Equals.
    GetHashCode , :
    Code:
    public int GetHashCode(string[] obj)
    {
        return obj[0].GetHashCode() ^ obj[1].GetHashCode();
    }


    EDIT2:
    :
    Code:
    public int GetHashCode(string[] obj)
    {
        return obj[0].GetHashCode() ^ obj[1].GetHashCode();
    }
    , , . , 1 .
    , , . :
    Code:
    d1.Add(new string[] { "a", "a" }, "47");
    d1.Add(new string[] { "b", "b" }, "b15");
    d1.Add(new string[] { "c", "c" }, "b15");
    GetHashCode , .
    , , , , "a", "b" "c" .
    Last edited by ; 28th December 2009 at 16:49.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |