So I have a button that calls a Class. The Method reads a file, stores the results in a Dictionary (tried Hashtable first and got the same error). I return the Dictionary variable. Then I try to loop through the results so I can save and reuse them later. For testing I am just trying to put the results into a listbox.
I'm getting the error: CS0030 Cannot convert type 'char' to 'System.Collections.Generic.KeyValuePair<string, string>'
Here is the code for the Class:
Expand|Select|Wrap|Line Numbers
- class getCharacter
- {
- public string getCharNow()
- {
- string fldr = "\\character.txt";
- fldr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + fldr;
- System.IO.StreamReader objReader;
- objReader = new System.IO.StreamReader(fldr);
- Dictionary<string, string> charProfile = new Dictionary<string, string>();
- do
- {
- string getLine = objReader.ReadLine();
- int findSplit = getLine.IndexOf(":");
- string heading = getLine.Substring(0, findSplit);
- string headingValue = getLine.Substring(findSplit + 1);
- charProfile.Add(heading.ToString(), headingValue.ToString());
- } while (objReader.Peek() != -1);
- objReader.Close();
- return charProfile.ToString();
- }
- }
Expand|Select|Wrap|Line Numbers
- private void getChar_Click(object sender, EventArgs e)
- {
- getCharacter getProfile;
- getProfile = new getCharacter();
- string profile = getProfile.getCharNow();
- foreach (KeyValuePair<string, string> pair in profile)
- {
- listBox1.Items.Add(pair.Key + " : " + pair.Value);
- }
- }
Also, I'm not sure if it matters or not, but the Class is not on the Button Form page (that may be normal or not, don't know). I just wanted to be able to call this Class from anywhere.
Again, I've very new to C# so I might be totally off on how I'm trying to do this. Any insight would be great. Thanks.