From the course: Advanced C#: Thread-Safe Data with Concurrent Collections

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Examine the ExampleQueue code

Examine the ExampleQueue code

- [Instructor] We're looking at the source code for this example queue. Remember, what I said earlier, is that I went to the Microsoft source code and I grabbed the small subset of what's in there type and added it to my custom class. So all I did was grab some fields. I also grabbed the enqueue, the dequeue, and the set capacity. This is used to add items to the queue. This is used to remove items from the queue. And this is used to change the size of the storage inside the queue. At the top are a number of fields. There's an array of T that holds the actual data. There's a head and tail that point to the first and last items in the queue. There's the size that knows the current size of the array. And then there's a version that is used for housekeeping. Here you can see there is an empty array defined on line 18. And then in the constructor of my queue, I take the empty array and assign it to the backing array. And…

Contents