|
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 .
|
|
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).
|
|
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....
|
|
Hi All,
I am getting confused as and when i come across a generic method of this sort?
public static <T> T addAndReturn(T element, Collection<T> collection){ collection.add(element); return element; }
The reason being is that i could not understand...
Started by Jegan on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Collection<int> intCollection = new Collection(); int addedInt = addAndReturn(5, intCollection as a single type is required obviously....
In the case you supplied T is the type of element you are adding to the collection.
That is returned.
|
|
Allright, this might be a strange question and maybe I am heading the wrong direction, but here is my problem:
I have a SearchForm object which holds a collection of Tag objects. When a Tag object is clicked by the user, it highlights itself and triggers...
Started by Max on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Most GUI frameworks, and the DOM itself that ....
If there's an item in a collection that needs to know about other items in the collection, it's perfectly reasonable for it to know about the collection as a whole as well.
With that.
|
|
I've been teaching myself LINQ recently and applying it to various little puzzles. However, one of the problems I have run into is that LINQ-to-objects only works on generic collections. Is there a secret trick/ best practice for converting a non-generic...
Started by BleuM937 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Data, so you don't have a full "collection" as such - but it's a perfectly fine data source for LINQ => match.Value.Length); }
If you have a collection which has some elements of the right type.
|