C# .net - Adding two integers gives wrong result
Ok, this is one of those errors I'm almost certain will have an obvious solution, but I've been banging my head for half hour now trying to figure out what's going on.
In C#.net, I'm trying to keep a total record count, which is simply a container for the number of records counted in a function.
I declare and initialise my total (iTotalRecords) as public so all functions can see it:
I then add records in the relevant place, at the same time adding to the total record:
public partial class MainWindow : Form
public string AppPath="";
public int iTotalRecords = 0;
public int iExpectedRecords = 0;
All fine so far, and I know that iRecords is counting correctly as the output file has the result in it.
trOut.WriteLine(entry.Substring(0, 3) + centre + entry.Substring(8, entry.Length - 8));
iRecords += 1;
iTotalRecords += 1;
However, when I later try to compare the two integers, iTotalRecords is coming out as exactly double what I would expect it to be, every time.
I've checked that I haven't done anything daft like added to iTotalRecords twice (I haven't BTW).
Can't think why it's doing this, it seems so simple!