c# how to add and remove a Point to a Queue -
can tell me how can add , remove point queue. because dequeue returns implicit error. f.e. queue q = new queue(); point = new point(0,0); point j = new point(0,0); q.enqueue(j); j = q.dequeue(); queue.dequeue returns object, need cast correct type: queue q = new queue(); point j = new point(0, 0); q.enqueue(j); while (q != null) //loop problem--see below { j = (point)q.dequeue(); } alternatively, can use generic version of queue , queue<t> . since queue of type declare, dequeue returns objects of type, there's no need cast: point j2 = new point(0, 0); queue<point> q2 = new queue<point>(); q2.enqueue(j2); j2 = q2.dequeue(); finally, while loop throw invalidoperationexception when execute, because after first dequeue, attempt dequeue again when queue empty.