Why doesn't my collection of strings (lst
) appear in the console? Visual Studio does not show any obvious errors. Please point out my mistake.
public partial class Home : Page {
public Home() {
InitializeComponent();
}
// ...
private void Button_Click(object sender, EventArgs e) {
Home.ABC();
MessageBox.Show("hello world");
}
static void ABC() {
List<string> lst = new List<string>();
OpenFileDialog opendialog = new OpenFileDialog();
opendialog.Multiselect = true;
bool? dialogResult = opendialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value) {
foreach (var file in opendialog.Files) {
Stream fileStream = file.OpenRead();
using (StreamReader reader = new StreamReader(fileStream)) {
while (!reader.EndOfStream) {
string line=reader.ReadLine();
lst.Add(line);
}
Console.WriteLine(lst);
}
}
}
}
}
The message box shows hello world
, so the function ABC()
also runs?