Currently I have a txt file where there are many lines, each of these lines can be a string, an integer, a line break, etc ... The fact is that I'm looking for a clean way to load lines that are integers in a list of integers.
Doing it by means of loops and comparisons is not a problem but I would like to do it using Linq.
I am currently at this point:
List<int> lista = new List<int>();
lista = streamReader.ReadToEnd().Split(' ').;
I can not find a way to filter from Split
I would also not care if the result was stored in an array of integers.
Edit: Doing it "in the rough", with loops and others works for me, it would look like this:
List<int> lista = new List<int>();
List<string> temp = new List<string>();
temp = streamReader.ReadToEnd().Split(' ').ToList();
for (int i = 0; i< temp.Count; i++)
{
if (temp[i].Length > 0)
{
int x = int.MinValue;
try
{
x = int.Parse(temp[i]);
if (x > int.MinValue)
lista.Add(x);
}
catch(Exception ex)
{ }
}
}