icollection

check whether an array is multidimensional

Hello, 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 CopyTo(MyClass[] array, int arrayIndex) I thought these brackets would mean that the given...

C# ICollection get single value

What is the best way to get a value from a ICollection? We know the Collection is empty apart from that. ...

What is the real advantage of returning ICollection<T> instead of a List<T>?

I've read a couple of blog posts mentioning that for public APIs we should always return ICollection (or IEnumerable) instead of List. What is the real advantage of returning ICollection instead of a List? Thanks! ...

Can iBATIS.NET work with ICollection?

Hi, This question is in relation to another question I have: http://stackoverflow.com/questions/603808/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 a custom collection of Bars) if it is a c...

Unittesting IList with CollectionAssert

The mstest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparantly a list is not a collection.. Are there ways to make my IList an ICollection? ...

Need Duplicates Allowed In SortedCollection (C#, 2.0)

Hello, I have a project that I'm working on that requires changing a 'BaseSortedCollection' class to allow duplicates. The class currently implements IEnumerable, IDisposable, ICollection, and ISerializable. The 'BaseSortedCollection' stores Items that have an ItemID (Int64), which is used as the key when accessing the collection. I n...

Why is HashSet<T>.IsReadOnly explicit?

This var h = new HashSet<int>(); var r = h.IsReadOnly; does not compile. I have to do var r = ((ICollection<int>)h).IsReadOnly; why wasn't IsReadOnly implemented normally? (I'm not asking how, but why) ...

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 an explanation for that? ...

Using LINQ with classes implementing non-generic ICollection

I wanted to run a LINQ query against a MatchCollection object but found this wasn't possible as it doesn't implement ICollection<T>, just ICollection. What is the best option for using LINQ with non-generic collections, both in terms of code conciseness but also performance and memory usage? (If interested, here is the non-LINQuified c...

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 but they are messy and involves wrapping ICollection in another interface and so forth. ...

What is the easiest and most compact way to create a IEnumerable<T> or ICollection<T>?

So, many times we have a function that accepts an IEnumerable or ICollection as a parameter. In cases where we have single items, but no collection to hold them, we must create a collection before passing them to the function, like: T o1, o2, o3; Foo(new T[] { o1, o2, o3 }); I've always created an array or a list, like I've done in th...

ICollection / ICollection<T> ambiguity problem

Just want to make simple extension for syntactic sygar : public static bool IsNotEmpty(this ICollection obj) { return ((obj != null) && (obj.Count > 0)); } public static bool IsNotEmpty<T>(this ICollection<T> obj) { return ((obj != null) && (obj.Count > 0)); } It works perfectly when I work with some collectio...

ICollection vs ICollection<T>- Ambiguity between ICollection<T>.Count and ICollection.Count

Note: This is similar, but not quite the same as this other question I've implemented an IBusinessCollection interface. It dervies from both ICollection<T>, and the old-busted non-generic ICollection. I'd prefer to just dump the old busted ICollection, but I'm using WPF databinding with a CollectionView which wants me to implement the o...

ICollection to String in a good format in C#

I have a List: List<int> list = new List<int> {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 str = list.Aggregate("[", (aggregate, value) => ...

T in class? AddRange ICollection?

I try to do static class, add to icollection but i got some issues i cant seem to overcome. that is how i get so i can pass a ICollection in the method? cause T is that say it can not be resolved. and then i wonder is there a way to do AddRange on icollection? i was thinking of something like this but maby i am way out of my mind with ...

Why ICollection index does not work when instantiated?

When we declare a parameter as ICollection and instantiated the object as List, why we can't retrive the indexes? i.e. ICollection<ProductDTO> Products = new List<ProductDTO>(); Products.Add(new ProductDTO(1,"Pen")); Products.Add(new ProductDTO(2,"Notebook")); Then, this will not work: ProductDTO product = (ProductDTO)Products[0]; W...

How do I implement an Delphi coded "ICollection" from a C# .NET collection defined within a 3rd Party Open API Tool.

How do I implement an Delphi coded "ICollection" from a C# .NET collection defined within a 3rd Party Open API Tool. I have a Laserfiche API toolkit where I am calling the code to return a collection of search hits. --- This is the process to call it from VB# --- search.BeginSearch(True) set results = search.GetSearchHits() ' retrie...

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

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<T>. Since I'm testing a repository for Entity Framework, and thus need to compare IObjectSet<T>s, that won't do - IObjectSet<T> doesn't imp...

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 M_refVerenUser_id; } And i am binding the data comes from db via the class above. private void ItemsGet() ...

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

Hi folks, 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<Foo> foos; This has a property called Status, which .. to keep things simple, is an int or byte (whatever floats your boat <-- see what I did there?...