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...
What is the best way to get a value from a ICollection?
We know the Collection is empty apart from that.
...
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!
...
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...
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?
...
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...
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)
...
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?
...
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...
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. ...
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...
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...
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...
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) =>
...
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 ...
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.
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...
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...
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()
...
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?...