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
3
votes
0 answers

Should ImmutableSortedSet throw an ArgumentNullException on Contains(null)

I have spent two days chasing down an evil bug. I narrowed down the problem with this test case demonstrating different behavior for different collection classes that implement the same interface. Specifically Contains(null) throws a…
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
3
votes
1 answer

check whether an array is multidimensional

as I am implementing the ICollection-Interface in my class I want to implement the CopyTo-Method and I have to throw an Argument-exception if the array is multidimensional. What is meant by this? The head of my method is this public void…
Sebastian Müller
  • 5,471
  • 13
  • 51
  • 79
3
votes
3 answers

Why I should not always be using ICollection instead of IEnumerable?

I ended up in this post while searching for solutions to my problem - which led me to propose a new answer there - and - to be confronted with the following question: Considering ICollection implements IEnumerable, and all linq extensions apply to…
Veverke
  • 9,208
  • 4
  • 51
  • 95
3
votes
2 answers

Problem With Repository Pattern & Abstract Classes

Come across a problem with the repository pattern combined with the use of abstract classes. I have a repository which implements a single method returning an ICollection of an abstract type. Here's my abstract class: public abstract class…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
3
votes
2 answers

How do you sort by a property of an ICollection?

I'm trying to figure out the display or LINQ call to an ICollection of a model parameter. Specifically here is my model for PurchReq (purchase requisitions): public enum FiscalYear { [Display(Name="2013")] LastYear, …
Aisarang
  • 31
  • 1
  • 2
3
votes
2 answers

Get ICollection property of generic type

I'm new in ASP.NET MVC 5, I need get the Icollection property and search into other property, if printed the result of the first search is fine, but when i go to search in the result is null. what is the problem? var userId =…
Maske
  • 824
  • 2
  • 17
  • 35
3
votes
2 answers

Cannot apply indexing with [] to an expression of type 'object' (even though the type is 'dynamic')

I have an ExpandoObject which is created like so: public ExpandoObject Get() { var expando = new ExpandoObject(); var expandoDic = (IDictionary)expando; // go through the items in the dictionary and copy over the key…
Maloric
  • 5,525
  • 3
  • 31
  • 46
3
votes
1 answer

Moq a virtual ICollection<> property that has a private set : "Invalid setup on a non-virtual"

I'm running into a problem where I try to mock an object which contain a property Items of type ICollection<>. I get the following error : System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: m => m.Items The…
ForceMagic
  • 6,230
  • 12
  • 66
  • 88
3
votes
1 answer

F# return ICollection

I'm working with a library created in C#. I've been working on porting some code to F# but must use quite a few underlying types from the C# lib. One piece of code needs to calculate a list of values and assign it to a public field/property in the…
Richard Todd
  • 2,406
  • 5
  • 32
  • 40
3
votes
3 answers

What is the advantage of return ICollection over List

Possible Duplicate: What is the difference between List (of T) and Collection(of T)? I have a static class and a getter to return my List Collection. Now I read and have been told to return ICollection rather than List. What is the advantage of…
Sylvia Rosemond
  • 197
  • 1
  • 3
  • 11
3
votes
1 answer

MinLength constraint on ICollection fails, Entity Framework

This is the datamodel I have: public class Team { [Key] public int Id { get; set;} [Required] public string Name { get; set; } [MinLength(1)] public virtual ICollection Users { get; set; } } My issue is that when I…
Automatico
  • 12,420
  • 9
  • 82
  • 110
2
votes
5 answers

.NET ICollection Class Basics

All, I have an application that needs to attach and detach multiple SQL databases regularly. I want to create a class that holds all of these databases as a collection that can be iterated over. To do this I am inheriting from ICollection, but there…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
2
votes
4 answers

Compare an ICollection members with itself

Is there any cheapest way to compare an ICollection with itself. Here is my code: public IEnumerable speciesChecker() { foreach (Pet pet in _pets) { bool wantedSpecies = true; …
Tabassum
  • 23
  • 3
2
votes
3 answers

Find an item inside a List by providing a sample object instance

Why is there a List.Contains(T) method but no List.Find(T) method? Only the Finds that support predicates are supported. If we have an existing instance of T populated with a property value for its ID (but missing other properties) why can't…
mare
  • 13,033
  • 24
  • 102
  • 191
2
votes
1 answer

.Net Core Web Api / HttpGet / About Get ICollection

Firstly, sorry for my English, it is not perfect. I hope i can explain my problem. WebApi has Movie Class like this public class Movie { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } …
Oguz
  • 31
  • 4