I'm trying to use the "Working with Comma-Separated Values" example program. However I'm not using a console application but a windows application.
I've taken the GetData method and placed it in Program.cs before Main. Then I copied the following two lines (from the example's Main) and placed it the form constructor:
Code:
public Form1() {
InitializeComponent();
List<string> columns;
List<Dictionary<string, string>> myData = GetData(out columns);
}
and place the rest of the code inside Form1 (writing to a textbox instead of console):
Code:
private void button1_Click(object sender, EventArgs e) {
foreach (string column in columns) {
textBox1.Text += column;
//Console.Write("{0,-20}", column);
}
textBox1.Text += "\r\n";
//Console.WriteLine();
foreach (Dictionary<string, string> row in myData) {
foreach (string column in columns) {
textBox1.Text += row[column];
//Console.Write("{0,-20}", row[column]);
}
textBox1.Text += "\r\n";
//Console.WriteLine();
}
//Console.ReadKey();
}
This give generates the error:
Quote:
|
Error 1 The name 'GetData' does not exist in the current context K:\visual_studio\learning_get_csv\learning_get_csv \Form1.cs
|
At this point I assume that the problem is that I'm no longer in "Program" but in a different class, "Form1", so I have to qualify the GetData method and change the line to:
Code:
List<Dictionary<string, string>> myData = Program.GetData(out columns);
Which changes the error to:
Quote:
|
Error 1 'learning_get_csv.Program.GetData(out System.Collections.Generic.List<string>)' is inaccessible due to its protection level K:\visual_studio\learning_get_csv\learning_get_csv \Form1.cs
|
Finally, grasping at straws, I make Program public:
Code:
static public class Program {
But this generates the same error. I'm dumb, I know, I just don't know how I'm dumb. Help? Please?
Thanks!!