Your queue is a queue of references to objects, not values of the object. Either clone the object and modify the cloned object when not working in the queue or don't modify the object after putting it in the queue.
Consider an analogy for further explanation. Imagine you have to keep track of 100 paintings. You choose to use a queue to keep track of all the paintings. You have two options to store the paintings in your queue:
- Pickup each paintings and move it into the queue
- Store the location of each paintings in your queue
Well option 1 is difficult because paintings are heavy are really big. Option 2 is much easier because all you need is a simple reference to each painting. However, with option 2, anyone can change the painting without going through the queue because the painting isn't actually in the queue. Option 1 is called pass by value. Option 2 is called pass by reference. And that is how C# stores objects in a queue.
Note: this analogy is imperfect, but it should help you understand what's happening.
The following code should help solve your problem:
object1 = 1;
queue.Enqueue(object1);
//Clone is a method you'll need to create on the class
//C# provides a MemberwiseClone method that should be very helpful
object2 = object1.Clone();
object2 = 2
MemberwiseClone
Alternatively, you could store your information with value types (int, char, bool, struct, etc) if you are storing simple and small information. Value types are stored in queues with option one (pass by value)
int a = 1;
var myQueue = new Queue<int>();
myQueue.Enqueue(a);
a = 2;
//Prints 1
Console.WriteLine(myQueue.First());
//Prints 2
Console.WriteLine(a);