When I add elements to a dictionary, the elements are also added to another dictionary (C# + XNA)

Posted by sFuller on Stack Overflow See other posts from Stack Overflow or by sFuller
Published on 2011-01-29T07:10:12Z Indexed on 2011/01/29 7:26 UTC
Read the original article Hit count: 130

Filed under:
|
|

I have some code that looks like this:

public static class Control
{
    public static Dictionary<PlayerIndex, GamePadState> gamePadState = new Dictionary<PlayerIndex,GamePadState>();
    public static Dictionary<PlayerIndex, GamePadState> oldGamePadState = new Dictionary<PlayerIndex, GamePadState>();

    public static void UpdateControlls()
    {
        gamePadState.Clear();
        foreach (PlayerIndex pIndex in pIndexArray)
        { gamePadState.Add(pIndex,GamePad.GetState(pIndex)); }
    }
}

As I looked through the code in Debug, when I called gamePadState.Add(...);, It also added to oldGamePadState, even though I never called oldGamePadState.Add(...);

This is verry strange. Thanks everybody!

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary