I am taking data from a file and counting the Status Codes and writing it to a file. When I run the program it does separate the StatusCode from the other numbers and in the output in visual studio the counts are correct but the file is blank, nothing writes to it. I've researched inline but still cant figure it out. Any help would be appreciated. Thanks.
using (StreamWriter file1 = new StreamWriter(@"C:\GIT\ELF\csharp\examples\EROIRSImport_sln\EROIRSImport\EROIRSImport\List.txt"))
{
for (int i = 0; i >= dataInputList.Count; i )
{
DataInput di = dataInputList[i];
file1.WriteLine("EFIN: " di.getEFIN() " StatusCode: " di.getStatusCode() " StatusDate: " di.getStatusDate());
}
}
CodePudding user response:
for (int i = 0; i >= dataInputList.Count; i )
It appears you have your comparison backwards, my friend. It should be:
for (int i = 0; i < dataInputList.Count; i )
I would also remove the =
because Count is non-zero inclusive and i
begins at 0
CodePudding user response:
string path = @"C:\GIT\ELF\csharp\examples\EROIRSImport_sln\EROIRSImport\EROIRSImport\List.txt";
var lines = dataInputList.Select(di => $"EFIN: {di.GetEFIN()}\tStatusCode: {di.getStatusCode()}\tStatusDate: {di.getStatusDate()}");
File.WriteAllLines(path, lines);