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

Performing operations on a List<> created from ICollection objects - ICollection objects are being changed

I'm trying to create a string with parts and quantities made from data contained in an ICollection. I'm using a List to build the totals I need but when I perform operations on this List it's actually changing the values in the ICollection. I…
BigBear2k
  • 19
  • 4
2
votes
2 answers

Why does not the generic counterparts of IList and ICollection have the same set of methods?

Is there a particular reason to why the generic counterparts of IList and ICollection do not have the same set of methods and properties? They seem to have moved them around. Ex. IList has int IndexOf(T item); void Insert(int index, T item); void…
Magnus
  • 45,362
  • 8
  • 80
  • 118
2
votes
1 answer

ICollection as argument: Provide List or Array

If some method requires an ICollection as an argument, but I have only an IEnumerable available: Is it better to convert this IEnumerable to a IList or is it better to convert it to an array T[] or shall I convert it to something else…
Sebastian Werk
  • 1,568
  • 2
  • 17
  • 30
2
votes
3 answers

Take unique records from text file using LINQ

I have set up ICollection list: public ICollection MyUsers { get; set; } public IList GetUserList(string path) { MyUsers = File.ReadAllLines(path) .Where(linia => linia.Length > 1) .Select(line =>…
4est
  • 3,010
  • 6
  • 41
  • 63
2
votes
3 answers

Is it possible to determine the current position when iterating an ICollection?

I have the following code: foreach(string reelid in unValidatedFeedersOnMachine.Keys) { _sqlString.Append("CompID = '").Append(reelid).Append("' "); } I need to add in that loop on each iteration .Appened("or ") except the last one. Any idea…
Night Walker
  • 20,638
  • 52
  • 151
  • 228
2
votes
2 answers

C# Converting object to List
I need to convert a list of string to a list of object, but the thing is I am receiving this list as an object, because it's a parameter and I don't know what type it is. This is the function that receives the parameter: public static bool…
tobi
  • 167
  • 1
  • 3
  • 12
2
votes
4 answers

c# add object array to ICollection - convert dto -> model

I need to convert this DTO public class MyDTO { [JsonProperty("studentInfo")] public StudentInfo studentInfo {get; set; } public class StudentInfo { [JsonProperty("others")] public ICollection Others { get;…
JAck28
  • 899
  • 4
  • 15
  • 40
2
votes
1 answer

LINQ related error "Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context

I have some code that is selecting some values from my database. I have a IQueryable of requests, that contains a ICollection of rooms. I want to get a List>. I have tried the following and i recieve the above error. Any…
mwild
  • 1,483
  • 7
  • 21
  • 41
2
votes
1 answer

Creating and editing a collection of strings using MVC3

Having some trouble understanding how to create and edit a collection of strings using a form. I've tried using EditorFor but it seems to have no luck and instead puts the following text into the form. I'm trying to edit the collection…
2
votes
1 answer

How to recursively traverse nested generic collection?

I want to count the number of a class in a nested collection, e.g. [[[1,2],[3,4,5]],[[1,2],[3,4,5]]]. Here the referred class is "int" and the expected answer is 10. I generate this list as: List list1 = new List(2); …
pengdlzn
  • 33
  • 7
2
votes
3 answers

Linq Conversion From ICollection to List

I am using Code First Entity Framework. I am using the following simple classes: public class Users { public ICollection Projects{get;set;} } public class Projects { public ICollection Users{get;set;} } I am using linq for…
Hassaan
  • 3,931
  • 11
  • 34
  • 67
2
votes
4 answers

how to use hashtable in Linq

I am trying to use hash table in linq to fetch the key whose value is ABC. What I have done so far: Hashtable h=new Hashtable (); h.Add(1 , "ABC"); h.Add(2 , "AgC"); h.Add(3 , "ABC"); h.Add(4 , "AhC"); Expected output: 1, 3 (keys having value…
user2623213
  • 233
  • 2
  • 4
  • 10
2
votes
0 answers

Exception with Custom expression builder with ICollection / IEnumerable

I have been trying to write a method that will build an expression based on types and parameters passed in. Currently the method is: // tuple: CollectionName, ClassName, PropertyName public Expression> BuildCollectionWithLike
user3161050
  • 111
  • 1
  • 14
2
votes
1 answer

How to use CollectionAssert (and Linq?) to find all the values for one property, are the same?

this is an extension to a previous question I asked, today .... which highlighted the use of CollectionAssert to help test collections (which I never knew). I have an ICollection foos; This has a property called Status, which .. to keep things…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
2
votes
1 answer

Binding LinqToSql tables to Repeater

I have a class which retrieves the data from DB. [Table(Name = "Ilanlar")] public class Ilan { [Column(Name="ilan_id" ,IsPrimaryKey = true)] public int M_ilan_id; [Column(Name="refVerenUser_id")] public int…
uzay95
  • 16,052
  • 31
  • 116
  • 182