This was the problem. I had filled an array of Char, Array1()with data and I wanted to sort it. However, I also wanted to keep a copy of the unsorted data to revert to.
The unexpected result of this code was that both Array1() and Array2() were sorted simultaneously!
As I later discovered, I was the victim of what is called a ‘shallow’ copy, and yes, there is a ‘deep’ copy which I will discuss, and demonstrate, later. But how and why did this happen? The answer, I’m afraid, lies deep in the Object hierarchy and in how Objects are stored in memory.
This is a very quick primer on how Objects inter-relate. Please feel free to skip the next few lines if I’m repeating what you already know.
We start by saying that (almost) everything in .NET is an Object (capitalisation intentional) – not just something we can describe as an object, but is derived from the Framework Class System.Object. The Object Class is the ultimate parent of each and every Object contained either within the Framework or which is derived from it.
Unfortunately, below the System.Object level, things get a bit more complicated and the idea of an Object having a Type must be introduced.