Original Post
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ListDemo
{
class ListDemo
{
static void Main(string[] args)
{
string path = null;
string fileName = @"ListOfStrings.txt";
if (path == null)
{
path = fileName;
}
else
{
path = path
+ "\\"
+ fileName;
}
if (!File.Exists(path))
{
Console.WriteLine("Error: File is missing: " + path);
return;
}
StreamReader sr = new StreamReader(path);
String inputLine;
List<string> myList = new List<String>();
while ((inputLine = sr.ReadLine()) != null)
{
myList.Add(inputLine);
}
sr.Close();
foreach (var item in myList)
{
Console.WriteLine("\n Element is {0}", item);
}
}
}
}
I try to load this text file:
987
10
12
276
My My
21.5
16.75
30
This
11
9
7
is
1
18
bad data
7
12
My question is how to skip the bad data in the text file (My My, This, is, bad data) and store them in a string list (using linq query). Thanks.