views:

131

answers:

1

I have used System.Collections.Queue and its object form_elements_queue

if (form_elements_queue.Count > 0)
      queue_element = (RecordQueue)form_elements_queue.Peek();

I'm modifying the queue_element like below,

queue_element.Children--;

RecordQueue is my custom Type which I Enqueue in form_elements_queue.

but its not referencing the Original Queue. How can I reference the queue_element to the original object which is in the queue.

+4  A: 

Is RecordQueue a struct or a class? If it's a class, it should be fine.

How are you checking whether the original queue has been modified?

Jon Skeet
You're right. If `RecordQueue` is a `class`, the code above will make a change in the object that's inside the queue. If it's a `struct` the code above will make changes to a copy of the value that's in the queue.
jpbochi
yes there you are, Its a structure :( I must use class ! right?
Tumbleweed
@Japan: Yes, using a class will solve this particular issue for you. You should almost always use classes anyway - it's very rarely a good idea to create your own struct, IMO.
Jon Skeet
but can anyone show me whats the best scenario where we should use struct instead of class ?
Tumbleweed
See http://msdn.microsoft.com/en-us/library/ms229017.aspx - but basically default to using classes, IMO.
Jon Skeet