473,657 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue<> implements ICollection but not ICollection<>?

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>?
May 10 '06 #1
3 2576
Dave,

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

I would register a bug over at the Product Feedback page.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Dave Booker" <db******@newsg roup.nospam> wrote in message
news:D8******** *************** ***********@mic rosoft.com...
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>?

May 10 '06 #2
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]

"Dave Booker" <db******@newsg roup.nospam> wrote in message
news:D8******** *************** ***********@mic rosoft.com...
| 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>?
May 10 '06 #3
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....

"Greg Young" wrote:
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#
"Dave Booker" <db******@newsg roup.nospam> wrote in message
news:D8******** *************** ***********@mic rosoft.com...
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>?


May 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3071
by: Luca | last post by:
I have the need of a container of integers showing both the characteristics of an associative container (all integer elements different from each other) and the FIFO behaviour. Do you know if there is a ready-made container for that or if I have to use - for example - a set<int> and produce by myself FIFO behaviour, or maybe I can use a queue<int> adding code for preventing the insertion od duplicate integers Thank you
7
3118
by: Dave | last post by:
Hello all, I'm pondering why the default underlying container for std::priority_queue<> is std::vector<>. It would seem that inserts are liable to happen anywhere, which would make std::list<> a superior alternative. Why factors am I not considering here? Why in the general case would std::vector<> be best? Thanks, Dave
11
5382
by: Charles L | last post by:
I have read that the inclusion of <fstream.h> makes the inclusion of <iostream.h> unnecessary. Is this correct? Charles L
1
2253
by: verec | last post by:
Last week I asked here how I could detect that a T was polymorphic, and received very thoughtful and useful replies that I used straight away. Thanks to all who answered. This week, it turns out that detecting whether T is polymorphic clashes with a new requirement, that T be allowed to not be complete. Last week, this code used to compile:
5
3538
by: tobbe | last post by:
Hi Im trying to load a XmlDataDocument with the following xml: <ROOT> <NAME> &LT; &AMP; &GT; " '</NAME> </ROOT> And i know I have a entity problem here, but i cant find any solution for it. The problem is that i recive this from external source and cant
22
130156
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
17
5316
by: Rainer Queck | last post by:
Hi NG, one more question about thread safety of generic lists. Let's assume a generic list: List<MyTyp> aList = new List<MyType>(); Would it be a problem if one thread removes elements from the list like MyTyp x = aList; aList.Remove(x);
3
6830
by: Alex Vinokur | last post by:
Is using memcpy() with queue<char> safe? ------ C++ code ------ #include <cstring> #include <iostream> #include <queue> using namespace std; int main() {
2
3369
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given field(s). The popping-up seems to work just fine; it's the tearing down that's giving me grief. If I stick a onmouseout event on the same input field that caused the onmouseover/pop-up, it starts to flicker 'cos the <divis placed for esthetically...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.