|
Hi,
What is the method in LINQ to supply a collection of values and check if any/all of these values are in a collection?
Thanks
Started by dotnetdev on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Bool containsAll = (list.Intersect....
List<T> shouldBeContained = ...
List<T> list = ...
I guess this is pretty inefficient but quick and dirty .
You can emulate this via .Intersect() and check if the intersection set has all the required elements .
|
|
In .NET (VB), how can I take all of the items in one collection, and add them to a second collection (without losing pre-existing items in the second collection)? I'm looking for something a little more efficient than this:
For Each item As Host In hostCollection...
Started by Matt Hanson on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
I know you're asking for VB, but in C# you can just use the constructor of the collection
Ben's solution does exist for VB.Net:
Dim collection As IEnumerable(Of T) Dim instance As New List(collection)
Here is the linked documentation....
|
|
What are the recommendations for exposing a custom collection vs generic one? e.g
public class ImageCollection : Collection<Image> { ... } public class Product { public ImageCollection {get; set;} }
VS
public class Product { public Collection<...
Started by Wololo on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Extensibility....
If you're building a public API, consider using a custom collection for the following advantages.
Are not interested responding to or watching these collection modifications then a List<T> is a more appropriate type.
|
Ask your Facebook Friends
|
I have a business object collection (representing data from the database) that inherits from Collection and has a static method that calls a stored proc and then populates its properties with the data returned.
My question is; is it wrong to inherit from...
Started by Si Keep on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Also, don't make the method....
Udate:
According to author's comments, publishing of all collection methods would make of the Collection.
If it's OK for your business object to provide usual collection methods to the world specify T .
|
|
Hi,
If do:
foreach(var a in col) { a.X = 1; }
Will my iterator over the collection become invalid?
Thanks
Started by Vando on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
What you can't do is modifying the collection itself (by removing or adding items to it) while iterating.
Your code is valid.
You can access the members of the items in the collection.
|
|
What is the best way to convert a non-generic collection to a generic collection? Is there a way to LINQ it?
I have the following code.
public class TestClass { } public class NonGenericCollection:CollectionBase { public void Add(TestClass a) { List.Add...
Started by J.W. on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Static List<TestClass> ConvertToGenericClass(NonGenericCollection collection) { return of a (possibly) heterogeneous collection, filter it with OfType<T>:
public static List<TestClass> ConvertToGenericClass(NonGenericCollection....
|
|
I have a concrete class that contains a collection of another concrete class. I would like to expose both classes via interfaces, but I am having trouble figuring out how I can expose the Collection<ConcreteType> member as a Collection<Interface...
Answer Snippets (Read the full thread at stackoverflow):
Usage looks like this:
Collection<INail> IBucket.Nails { get { return new .
collection, converting values to the required type (doesn't require copying all list values to the new collection).
|
|
I am looking for an abstract data structure which represents a collection of sets such that no set in the collection is a subset of another set in the collection.
This means that on insert the following conditions will be met:
A. Inserting an element ...
Started by Mark Wassell on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Add S if you get to the end of the... .
For each existing entry E in the collection of sets, stop if p(S) < p(E) exactly.
Adding a new set S to the existing collection time regardless of N.
Bc is a subset of abcd (as are sets abd and abc) .
|
|
If all attributes (or items fields, or data members) of a java collection are thread-safe ( CopyOnWriteArraySet , ConcurrentHashMap , BlockingQueue , ...), can we say that this collection is thread-safe ?
an exemple :
public class AmIThreadSafe { private...
Started by wj on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
To use this function to ensure thread-safety:
synchronizedCollection(Collection c) Returns a synchronized (thread-safe) collection backed by the specified collection
Reading that, it is my opinion that you have to use the above function....
|
|
I am aware of http://stackoverflow.com/questions/1174328/passing-a-generic-collection-of-objects-to-a-method-that-requires-a-collection-of
How do I do it in .Net 2.0 where I don't have .Cast ???
It has to be reference equality i.e. copies of the list ...
Started by kpollock on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
In fact, you could.
If it's your collection (as in you can modify the collection class) you can implement IEnumerable(Of WhateverBase) even if your collection derives from Collection(Of Whatever).
Though.
|