I have two forums,Login and Game.
Login is used for logging in and it calls a dictionary from class "Clsdictionary"
So I use this on Form Login.
clsDictionary UserSetCLS = new clsDictionary();
|
Then I add some Values and Keys to that Dictionary in the class,I'm using a class so this dictionary can be global/Shared between all my forms in that application.
ClsDictionary.cs code
public Dictionary UserSetSTRING = new Dictionary(); public Dictionary UserSetINT = new Dictionary();
|
Then in form login i add some keys and values
UserSetCLS.UserSetINT.Add("UserID", _UserID); UserSetCLS.UserSetSTRING.Add("UserName", UserName); UserSetCLS.UserSetSTRING.Add("CapitalName", CapitalName);
|
Now I have 3 entries.
1 for UserSetINT
2 for UserSetSTRING
At the end of all my code it switchs to form game.
I try to call back the entries that SHOULD be in the Dictionary
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace Game { public partial class frmCapitalCity : Form { clsDictionary UserSetCLS = new clsDictionary(); string CapitalName; public frmCapitalCity() { InitializeComponent(); }
private void CapitalCity_Load(object sender, EventArgs e) { UserSetCLS.UserSetSTRING.TryGetValue("CapitalName", out CapitalName); } } }
|
So that should take the dictionary entry "CapitalCity" and change the label I have to the string value of that.
But,When i call it back its Null. I'm wondering how could that be? I put it all in another Class so it can be used in every form in my application.
Basicly All i want to do is Get one Value from one forum to another.
On Login the Dictionary count is 3 with those three values and there keys.
When i call it back on Game the count is zero with no Entries!
Can anyone correct me in what i did?
Or
Point me to a tutorial that goes over this Specific detail of what i want to do?
If you need me to clear anything up please post!
Thanks,
Aaron
PJ MartinsPosted Jun 1, 2010, 3:27 PM
public static ClsDictionary Instance = new ClsDictionary();
now you can access the instance throughout your project, so in your login form you'd use:
ClsDictionary.Instance.UserSetINT.Add("UserID", _UserID);
ClsDictionary.Instance.UserSetSTRING.Add("UserName", UserName);
ClsDictionary.Instance.UserSetSTRING.Add("CapitalName", CapitalName);
and in frmCapital you'd do this instead:
ClsDictionary.Instance.UserSetSTRING.TryGetValue("CapitalName", out CapitalName);
PJ MartinsPosted Jun 1, 2010, 5:46 PM
ClsDictionary.Instance.UserSetINT.Count;
AaronPosted Jun 1, 2010, 5:10 PM
That got the job done.
I'm kind of confused on how to view the count of the dictionary now from the "Locals" Listing.
But,Then again when it reaches the other side i can see if its correct or not.
Everything works now and i took out
clsDictionary UserSetCLS = new clsDictionary();
on both the login and the Capitalcity due to after your code its useless to instance it at the top!
Thanks again!