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());

VulpesRank #55 · 29.2K reputationPosted Nov 11, 2013, 12:00 AM EST
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.
csharp beginner38 reputationPosted Nov 11, 2013, 7:05 AM EST
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());
}
csharp beginner38 reputationPosted Nov 11, 2013, 7:15 AM EST
VulpesRank #55 · 29.2K reputationPosted Nov 11, 2013, 9:58 AM EST