Using this method I am looping through a file removing lines with a 'T'
in them and storing them to a list. At the end of the loop it should exit, however it reads the null
value and continues to pass it throwing an exception with message...
System.ArgumentNullException: 'Value cannot be null. Parameter name: source'
... at the point where it tries to look for the char.
public static List<string> GetToolsFromFile()
{
FileStream FS = new FileStream(OpenFile(), FileMode.Open);
List<string> list = new List<string>();
using (StreamReader Sr = new StreamReader(FS))
{
char c = 'T';
while (Sr.ReadLine() != null)
{
string line = Sr.ReadLine();
//MessageBox.Show(line.ToString());
if (line.Contains(c))
{
list.Add(line);
// MessageBox.Show(line.ToString());
}
}
FS.Close();
}
return list;
}
The OpenFile()
is a method using the OpenFileDialog
. This was tested and working as it retrieves and displays the contents of the selected file.