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
1
vote
1 answer

Why does not WhereSelectArrayIterator implement ICollection?

In looking at System.Linq.Enumerable through Reflector i noticed that default iterator used for Select and Where extension methods - WhereSelectArrayIterator - does not implement ICollection interface. If i read code properly this causes some other…
1
vote
1 answer

How to use polymorphism with a list of lists in C#

I am having trouble using polymorphism with a list of lists of int in C#. I need the "external" list to be able to add/remove "internal" lists, but the "internal" lists don't need to change. So I thought about using a variable type…
1
vote
1 answer

Entity Framework: multiple dbcontext or not? And a few other performance related question

I’m build a calendar/entry/statistics application using quite complex models with a large number of relationships between models. In general I’m concerned of performance, and are considering different strategies and are looking for input before…
1
vote
1 answer

Can iBATIS.NET work with ICollection?

This question is in relation to another question I have: Using iBATIS.NET with generic custom collection interfaces and Unity The problem seems to be that iBATIS.NET will only populate a custom collection (i.e. QueryForObject("Select_Foo") which has…
tRi11
  • 149
  • 8
1
vote
1 answer

Compare two ICollection without splitting it into subranges?

I am currently in a situation where i need to compare two ICollection, and validate a) whether the second contains the same items as the first one, b) and if there is an extra element, ensure that it can be vali dated using a validation method.…
kafka
  • 573
  • 1
  • 11
  • 28
1
vote
3 answers

Determining if a call to ICollection Count will result in iteration

Suppose I want to access an object from a Collection, and I want to be sure it doesn't iterate through the whole Collection just to determine the size. How can I determine and control if a call to Count results in actually iterating though the…
HCP
  • 1,012
  • 2
  • 11
  • 18
1
vote
3 answers

Why use ICollection over IList?

I've read articles that say use ICollection if you want the functionality of IEnumerable, but also want the Count property. However since the extension methods in System.Linq.Enumerable provide methods such as ElementAt(), why wouldn't you…
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
1
vote
1 answer

How should i use collection?

I have a list of strings which is populated by a query from database (entity frameworks): var accountIds = new List(); Now I want to add two list of strings to my collection, for example, I have these two queries: using (var myketDB = new…
Ali Eshghi
  • 1,131
  • 1
  • 13
  • 30
1
vote
1 answer

Why don't array types have Add() method although they implement IList?

Array types such as int[] implement many interfaces, and IList is one of them. IList requires to implement the Add(T) method (because IList inherits from ICollection). I am writing a "CircularArray" class which contains an array in itself, but…
1
vote
3 answers

Find specific item on icollection

I'm working on an web api and trying to find a product by it's name with icollection, specifically a product that would match the name given (?name={name}). Currently I have this: [HttpGet("name", Name = "GetProductByName")] public…
idetodospoca
  • 73
  • 3
  • 12
1
vote
3 answers

Can't convert System.Object[] to System.Collections.Generic.List

I have a method with an object parameter. public bool ContainsValue(object value) I found that converting the object to an IList works. IList list = (IList)value; However, converting it to a List does not. List Ilist =…
Benjamin
  • 291
  • 3
  • 12
1
vote
2 answers

How do I serialize this IEnumerable to JSON? ( DnnApiController )

Issue The problem I'm having is that when returning "treeNode" after building it, it doesn't serialize when sent down the wire via API. The object [and nested elements] looks great while debugging but when the browser receives the data for the tree…
Cody Tolene
  • 127
  • 1
  • 1
  • 10
1
vote
1 answer

Iterate through ICollection

I would like to iterate through all voices that are installed on a device. In the TextSoSpeech metadata I see that there's namespace Android.Speech.Tts { public class TextToSpeech : Java.Lang.Object { [Obsolete("deprecated")] …
tw2017
  • 105
  • 1
  • 6
1
vote
1 answer

How to group by a nested property of ICollection in LINQ?

I need some help... I have an Entity with an ICollection nested, when I need to make a group by of Work (AdjudicationHead) and AdjYearFFI I cannot set AdjYearFFI as property to group. Entities: public class AdjudicationHead : BaseEntity { …
1
vote
1 answer

Convert an IEnumerable> to an IEnumerable

I'm trying to convert an IEnumerable> to an IEnumerable knowing that TParent object contains a ICollection. I started this way but I really don't now how to normalize the results : for (int i = 0; i <…
user3574857
  • 377
  • 4
  • 16