Questions tagged [icollection]

The ICollection interface is the base interface for classes in the System.Collections namespace. It defines size, enumerators, and synchronization methods for all non-generic collections

The ICollection interface is the base interface for classes in the System.Collections namespace.

The ICollection interface extends IEnumerable; IDictionary and IList are more specialized interfaces that extend ICollection. An IDictionary implementation is a collection of key/value pairs, like the Hashtable class. An IList implementation is a collection of values and its members can be accessed by index, like the ArrayList class.

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

If neither the IDictionary interface nor the IList interface meet the requirements of the required collection, derive the new collection class from the ICollection interface instead for more flexibility.

279 questions
4
votes
2 answers

Creating my own "LINQ" extension methods

so I was wondering if someone would make a very thorough explanation of what exactly I have done here, I know what im working with, and what the meaning of the code is, however, if I were to explain it, I would be clueless. public static…
user6843589
4
votes
1 answer

Arrays vs Generic in C#

I have noticed that array, in c#, implements ICollection. How can an array implement a generic container interface, yet not be generic itself? Is it possible for us to do the same? Edit: I would also like to know how the array is not generic, yet…
Maderas
  • 231
  • 2
  • 14
4
votes
3 answers

Casting ICollection of a concrete type to an ICollection of the concrete type interface

What is the recommended way to cast an ICollection to ICollection where Bar implements IBar? Is it as simple as collection = new List(); ICollection = collection as ICollection? or is there a better way of doing it?
Graham
  • 1,497
  • 2
  • 16
  • 36
4
votes
3 answers

Replacing an element in ICollection

Suppose I have an ICollection. I have the following two variables: SomeClass old; SomeClass new; How can I achieve something like the following using an ICollection? // old is guaranteed to be inside…
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
4
votes
1 answer

Posting Nested Collection to Web API

I'm trying to post a complex type object to web api. On the web api side, when method recieves the object parameter, every property is set properly except a collection that is derived from ICollection. Here is my sample classes: public class…
caranhithion
  • 55
  • 4
  • 7
4
votes
5 answers

What is the most basic class that inherits ICollection

I need a generic collection class which I can add to, and enumerate over. Since ICollection inherits from IEnumerable, the class really just needs to inherit from ICollection. Is there a simple generic class in the BCL that just inherits…
Marty Neal
  • 8,741
  • 3
  • 33
  • 38
4
votes
2 answers

Is it possible to use Microsoft.VisualStudio.QualityTools.UnitTesting.CollectionAssert on an IEnumerable?

I have a testing scenario where I want to check if two collections are equal. I have found the class Microsoft.VisualStudio.QualityTools.UnitTesting.CollectionAssert, but it only works on ICollection. Since I'm testing a repository for Entity…
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
4
votes
1 answer

ICollection to string array (using string property)

I have an ICollection of Thing. Thing has a string property Name. I would like to get an array of all Name in my ICollection. I know I can do this by iterating over the collection and building the array, but is there a neater way to do this with…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
4
votes
6 answers

Is there a nice simple & elegant way to make ICollection more fluent in C#?

Example: I would like to have the Add method of ICollection of a custom collection class to implement method chaining and fluent languages so I can do this: randomObject.Add("I").Add("Can").Add("Chain").Add("This"). I can think of a few options…
danmine
  • 11,325
  • 17
  • 55
  • 75
4
votes
3 answers

For LINQ Performance Gurus- Searching through non-generic ICollection

I need to search through a collection of "Item" objects that contain a time property. I have a fast solution in place but its very messy (will post if nothing better comes up). Below are my attempts at performing the search myself using LINQ and…
user1002479
  • 235
  • 2
  • 4
  • 12
4
votes
2 answers

What happens when casting IEnumerable to ICollection

Given a case such that: var collection = myEnumerable as ICollection; What happens under the hood? ICollection has a count property. Does this casting enumerate the enumerable to get the count or does something more involved happen?
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
3
votes
1 answer

Get last step in component wizard

C# Wizard control has the event ActiveStepChanged that is triggered when we move through the steps of the wizard. The current step is stored in the property called ActiveStepIndex. I need to retrieve the step immediately preceding the current…
Marco
  • 77
  • 7
3
votes
5 answers

Easiest way to get "next" element in a sequence?

I've got an ICollection. public class SomeClass { public string Text { get; set; } public bool IsPreferred { get; set; } } The items in there have been pre-ordered, so "next" does mean something. In my scenario, the contents of the…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
3
votes
1 answer

Filter list of objects, where nested collection matches an array

I have a list of objects (items) which I would like to filter basis the values of a nested collection (Features in object GenericItem). As basis for the filter I have an array of int (filter). My objective is to find all objects in items where the…
Superman.Lopez
  • 1,332
  • 2
  • 11
  • 38
3
votes
2 answers

Not grasping what ICollection does in C# after looking through documents

After looking for hours on Microsoft and on StackOverflow, I'm seriously not getting the reasoning on why ICollection is another class in the coding. For example, why is there an ICollection of Book and a new list of books in the Author.cs file? I'm…
user6793735