Okay, i've searched EVERYWHERE and I'm truly stuck with this. I'm trying to create a program which will load a CSV file with text words separated by a comma using a streamreader and then add them into a dictionary. Then on the form if a user types the text before the comma into the first text box and clicks a button then the text after the comma will show in the other text box.
I'm not going to lie, I'm still trying to learn to basics of c# so an explained answer would be appreciated!
This is my code just now and I don't know where to go from here, I want to use a TryGetValue after the comma split to assign the first part of the text as [0] and the second part after the comma as [1]
//Dictionary Load Button
private void button1_Click_1(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK) // Allows the user to choose the dictionary to load
{
Dictionary<string, int> d = new Dictionary<string, int>();
using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] splitword = line.Split(',');
}
}
}
}
an example of my input data is like:
black, white
cat,dog
yellow, blue