I have a string that is args[0]
.
Here is my code so far:
static void Main(string[] args)
{
string latestversion = args[0];
// create reader & open file
using (StreamReader sr = new StreamReader("C:\\Work\\list.txt"))
{
while (sr.Peek() >= 0)
{
// code here
}
}
}
I would like to check if my list.txt
file contains args[0]
. If it does, then I will create another process StreamWriter
to write a string 1
or 0
into the file. How do I do this?
Code to work:
Are you expecting the file to be particularly big? If not, the simplest way of doing it would be to just read the whole thing:
Or:
Alternatively, you could read it line by line:
Or even more LINQ-like:
Note that
ReadLines
is only available from .NET 4, but you could reasonably easily callTextReader.ReadLine
in a loop yourself instead.