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
2
votes
2 answers

How to add a string to a ICollection?

EDIT 2 I have got some help over the past few days on a problem that I am trying to work through. After receiving helpful support from several users, I have come across an error that I have been trying to fix over the weekend and still not…
Ben
  • 245
  • 4
  • 13
2
votes
0 answers

How to implement IXmlSerializable correctly for a ICollection where T is an abstract class?

I'm trying to implement IXmlSerializable interface in a Collection of T where T is an abstract class. My scenario is this: I've got a abstract class BaseClass which implements IXmlSerializable Two derived clases (Deriv01, Deriv02) which inherits…
2
votes
2 answers

Filtering ICollection

This code doesn't work, but: public virtual ICollection items { get { return (ICollection)items.Where(e => e.isVisible == true); } set { ;} } I'd like to do something to that effect. So to get an ICollection filtered by a…
Tyler Durden
  • 2,031
  • 4
  • 20
  • 25
2
votes
5 answers

ICollection to String in a good format in C#

I have a List: List list = new List {1, 2, 3, 4, 5}; If want to get string presentation of my List. But code list.ToString() return "System.Collections.Generic.List'1[System.Int32]" I am looking for standard method like this: string…
AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
2
votes
2 answers

.net - dictionary.Keys.Add?

In .Net, IDictionary defines .Keys and .Values properties, each of which is an ICollection<> rather than IEnumerable<>, which seems like it would be a more natural fit to me. Is there any reasonable use case to call .Add or .Remove on .Keys or…
recursive
  • 83,943
  • 34
  • 151
  • 241
2
votes
3 answers

C# IDictionary.Keys and IDictionary.Values: what is the most optimal implementation?

I have a C# class that acts as a dictionary so I'm now in the process of supporting IDictionary. Everything is fine except for the properties Keys and Values: ICollection Keys { get; } ICollection Values { get; } I don't have a…
Éric
  • 181
  • 2
  • 15
2
votes
1 answer

MVC3: Pass ICollection from View to controller

I have a model with an property of type icollection. public class myClass{ public string param1{get; set;} public string param2{get; set;} public virtual ICollection param3{get; set;} public myClass() { param3 = new…
jpo
  • 3,959
  • 20
  • 59
  • 102
2
votes
1 answer

Why is the `IDictionary.Values` property of type `ICollection`?

I'm trying to wrap my head around why the IDictioary.Values property is of type ICollection as opposed to IEnumerable. The .NET implementation of the Values property implements the interface property explicitly and then…
Anthony
  • 9,451
  • 9
  • 45
  • 72
2
votes
2 answers

MVC delete removing unrelated data

I am trying to delete some data (how hard can it be, anyway?) but whenever I remove a complex-type prop from my model object, the contents of an ICollection prop are also mixed. Here's the code: [HttpPost, ActionName("Delete")] public…
Bondolin
  • 2,793
  • 7
  • 34
  • 62
2
votes
3 answers

I can not access Count property of the array but through casting to ICollection !

int[] arr = new int[5]; Console.WriteLine(arr.Count.ToString());//Compiler Error Console.WriteLine(((ICollection)arr).Count.ToString());//works print 5 Console.WriteLine(arr.Length.ToString());//print 5 Do you have…
Ahmed
  • 7,148
  • 12
  • 57
  • 96
1
vote
1 answer

How to unbox a box to an ICollection with an unknown type?

I have a IRecord object that can hold objects. The name of these objects is saved in mapping as Properties. I loop through the properties and get them out of the IRecord by doing record[property] These objects are always ICollections. However, I…
Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
1
vote
1 answer

Route event From Item to a Collection in MVVM

How can I do something like this? public class person { public ICommand Add_as_Friend { get; private set; } public event EventHandler C1_Friend_Add; //.... Add_as_Friend = new Command(Handle_Add_FR, HandleCan_Add_FR); void…
1
vote
1 answer

Casting a List (where T : IBar) to ICollection fails

I have classT, implementing interfaceIBar. I have a variable list of type List. Two questions for enhancing my understanding of the language: Why doesn't this work? var foo = (ICollection )list; // fails! How to work around it (if…
Konrad Morawski
  • 8,307
  • 7
  • 53
  • 91
1
vote
1 answer

Limited size IList or ICollection that when adding a new item, first item is discarded

I'm looking for some sort of implementation of IList or ICollection that behaves in such a way that it can hold up to a specified amount of items. If adding a new item would exceed the limit-amount, the first item should be automatically…
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
1
vote
1 answer

How to loop multiple ICollection use recursive (Backtracking)

Suppose class Menu use property ICollection Items { get ; set ; } . It is representing data field in mongodb . When insert data and show it will have the following structure: I want loop from N1 to N1-child1,child2,child3,....…
Muon Roi
  • 17
  • 5