Queue<> implements ICollection but not ICollection<>?

G

Guest

Am I missing something here? It looks like the generic Queue<T> implements
Enumerable<T> and ICollection but not ICollection<T>. (I want to use it in
an interface that wants an ICollection<T>.)

Is there a reason for this, or is it just an oversight in .NET 2.0?

Is there a computationally easy way to cast/convert a Queue<T> to an
ICollection<T>?
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

Unfortunately, it looks like it was overlooked. Quite pathetic in my
opinon.

I would register a bug over at the Product Feedback page.
 
W

William Stacey [MVP]

Could be wrong, but ICollection<T> would make a queue more like a list then
a queue. Queue does not have a Remove(item) method, but ICollection<T>
does. So that would wreck the symantics of Queue which only have Enqueue
and Dequeue to add item to end and remove item from top - so Remove(item)
does not fit with Queue.

--
William Stacey [MVP]

| Am I missing something here? It looks like the generic Queue<T>
implements
| Enumerable<T> and ICollection but not ICollection<T>. (I want to use it
in
| an interface that wants an ICollection<T>.)
|
| Is there a reason for this, or is it just an oversight in .NET 2.0?
|
| Is there a computationally easy way to cast/convert a Queue<T> to an
| ICollection<T>?
 
K

Kevin Yu [MSFT]

Hi,

I saw you opened a bug to the product team. I think they will give you a
response as soon as possible. Thank you for your feedback. You can check
the response from the following link

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=6
8f6bc13-8bab-4079-b3eb-f85d2075c6d2

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Greg Young

This is not a bug it is by design and it is documented.

From: http://msdn2.microsoft.com/en-US/library/92t2ye13.aspx

"Some collections that limit access to their elements, like the Queue class
and the Stack class, directly implement the ICollection interface."

If you look, the interfaces are also very different from each other in what
they include. The generic one includes methods such as ...

Add, Remove, Clear

Which do not exist on the non-generic ICollection.

I would agree that the terminology is a problem but the class is implemented
as it should be.

Cheers,

Greg Young
MVP - C#
 
G

Guest

OK, I see what you mean: I.e., despite the linguistic similarities,
ICollection<> is NOT a generic ICollection.

Well, I would like to have a generic ICollection. And surely there's a use
for what they decided to call the ICollection<>, but probably under a
different name? I guess I'll leave it to the far more enlightened architects
to clear this up....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top