Blog Stats
  • Posts - 99
  • Articles - 5
  • Comments - 236
  • Trackbacks - 105

 

ICollection and ICollection<>

Eralier I posted (and deleted) about the Queue class not implementing ICollection from some research this is by design.

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, and Clear which do not exist on the non-generic ICollection.

So conclusion .. Queue is correct but I have to say that having the generic and non-generic ICollections that represent completely different things is a bit confusing at best :-/

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

# re: ICollection and ICollection<>

Gravatar I don't want to cast it or have to explicitly state the type. I just want to use var and have clean code. As far as that goes, ICollection<string> counter is the same as var counter = (ICollection<string>), and doesn't solve the issue .
Thank you.
i hope you also like it.....
Free Nifty Tips 3/15/2011 2:50 AM | Intraday Share Tips

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Greg Young