So I have a list with some data in it such as an input path, output path as well as column headings. As can been seen there are six column headings however some may be null as they do not have to be used. Because of this I created a method to filter the data so that only useful data remains.
List<string> data = new List<string> { "C:/", "C:/Documents", "Hello", Goodbye". null, null, null, null } // Data to be passed into method
List<string> filteredData = new List<string>();
public void FilterData(List<string> data)
{
foreach (var d in data)
{
if (d != null || d != String.Empty)
{
filteredData.Add(d);
}
}
}
Why is it that when I pass the List data into this method none of the data is filtered so that filteredData will contains the same as data, but when I use the following (if statement only evaluates if not null) it filters correctly?
public void FilterData(List<string> data)
{
foreach (var d in data)
{
if (d != null)
{
filteredData.Add(d);
}
}
}
Thanks
Aucun commentaire:
Enregistrer un commentaire