xxfogs
xxfogs

Reputation: 79

Dictionary doesn't returns value from different class when it contains it

Im attempting to save information about users SteamID and his position in game, here is the code through which I teleport the person to the saved position each 0.5 seconds, and it works perfectly returning this information in console

Key: 76561198333850828, Value: (605.0, 41.8, 618.5)

  IDictionary<Steamworks.CSteamID, Vector3> numberNames = new Dictionary<Steamworks.CSteamID, Vector3>();

                        while (numberNames.Count > 0)
                        {
                            foreach (KeyValuePair<Steamworks.CSteamID, Vector3> info in numberNames)
                            {
                                UnturnedPlayer steamidplayer = UnturnedPlayer.FromCSteamID(info.Key);
                                steamidplayer.Teleport(info.Value, 0);
                                Console.WriteLine("Key: {0}, Value: {1}", info.Key, info.Value);
                                await Task.Delay(TimeSpan.FromSeconds(0.5));
                            }
                        }

Yet when I attempt to remove the information from dictionary in a different class it says that dictionary does not contain anything

        internal void remname(Steamworks.CSteamID SteamID)
        {
            if (numberNames.ContainsKey(SteamID))
            {
                numberNames.Remove(SteamID);
            } else
            {
                Console.WriteLine("Doesnt contains");
            }
        }

And I have absolutely no idea what might have possibly caused this problem.

Upvotes: 2

Views: 63

Answers (1)

bwakabats
bwakabats

Reputation: 703

How have you defined numberNames? If there are 2 definitions, one in each class, then they are completely different objects even though they share the same name.

Even if there is one definition in one class then, unless it is static different instances of the same class will have different objects.

Upvotes: 5

Related Questions