In the following condition: after a point it takes all the values to be '0'. Can anybody tell why it is happening?
var csv = new StringBuilder();
var csv = new StringBuilder();
for (int i = 0; i <= terms.Length; i++)
{
if (terms[i] == firstlistA[i])
{
string first = terms[i];
string second = firstlistB[i];
var newLine = string.Format("{0},{1}{2}", first, second, Environment.NewLine);
csv.Append(newLine);
}
else
{
string first = terms[i];
string second = "0";
var newLine = string.Format("{0},{1}{2}", first, second, Environment.NewLine);
csv.Append(newLine);
}
File.WriteAllText(sfd.FileName, csv.ToString());
VulpesPosted Nov 11, 2013, 2:58 PM
csharp beginnerPosted Nov 11, 2013, 12:15 PM
csharp beginnerPosted Nov 11, 2013, 12:05 PM
Sorry for i didn't put my question properly before. But, i would like to tell you that, i have found my mistake. There was a little iteration and incrementing problem. I have solved it.
Here, the codes modified:
int j = 0;
var csv = new StringBuilder();
for (int i = 0; i <= terms.Length; i++)
{
if (terms[i] == firstlistA[j])
{
string first = terms[i];
string second = firstlistB[j];
j++;
var newLine = string.Format("{0},{1}{2}", first, second, Environment.NewLine); csv.Append(newLine);
}
else
{
string first = terms[i];
string second = "0";
var newLine = string.Format("{0},{1}{2}", first, second, Environment.NewLine);
csv.Append(newLine);
}
File.WriteAllText(sfd.FileName, csv.ToString());
}
VulpesPosted Nov 11, 2013, 5:00 AM
However, what is clear is that if terms contains nothing but "0" after a certain point and firstlistA contains no "0" after that point, then the 'else' block will apply and the file will be filled with 0,0 lines from that point onwards.