collections

Applying Action Delegate

Just to understand the collection ,I tried to find the square of each number passed in to a collection. My Code is (Ofcourse I could have implemented in differ way,Just to know casting itretaions,I have made a dummy implementation). static void Main() { ICollection<int> Present = (ICollection<int>) ...

Is the Apache Commons Collections framework faster than the JDK collections framework?

I have always been using the stock JDK collections in my code. Does the Apache Commons Collections framework run faster? ...

Java Hash Collection

There is a class called HashSet in Java For example, I'll add following int-shaped value to HashSet, [input] 1,2,3,4,5,6,1,2,3,1, [hash structure] 1,1,1 2,2 3,3 4 5 6 Is there the collection to become such a structure? ...

New Collection interfaces in C# 3.0

What are the new collection interfaces available in C# 3.0 ? In C# 2.0 IComparer IEqualityComparer IEnumerator IEnumerable ICollection IDictionary IDictionaryEnumerator IList. ...

Synchronization of ICollection

When observe the definition of ICollection extends IEnumerable. It provides size and synchronization members in addition to enumeration. Does synchronization here represent the synchronization of collection ,when it is shared by multiple threads?.Kindly explain me with simple example how can i practically use "ICollection.IsSynchron...

Get last element in a SortedDictionary

I see this question. How can I get the last element in a SortedDictionary in .Net 3.5. ...

Overloading of GetEnumerator

Can't i overload GetEnumerator () like IEnumerator<T> IEnumerable<T>.GetEnumerator<T> ( T[] val1,T[] val2) { .... some code } ...

UserControl array, each control has a method to set the text of a label there, but getting a NullReferenceException. Help!

So, I create an array: TorrentItem[] torrents = new TorrentItem[10]; The TorrentItem control has a method called SetTorrentName(string name): private void SetTorrentName(string Name) { label1.Text = Name; } I'm using a for loop to populate 10 TorrentItems like so: private TorrentItem[] GetTorrents() { TorrentItem[] torrent...

Ways to fill a list in Java

Hi, I would like to know your opinions on which you find is a better approach to have a list filled up by a different method. I know there isn't a definite answer, but I would like to see reasonable pros and cons. Approach 1. private List<Snap> snapList; snapList = getSnapList(); Approach 2. private List<Snap> snapList = new ArrayL...

Limit a ListIterator to the first N elements (optimized)

What is a simple and fast way to get an iterator that returns at most N elements from the start of a List? The simplest versions I could come up with are: #1: import com.google.common.collect.Iterators; // ... public static <E> Iterator<E> lengthLimitedIterator(Iterable<E> source, int maxLen) { return Iterators.partition(source....

Getting a KeyValuePair<> directly from a Dictionary<>

I have System.Collections.Generic.Dictionary<A, B> dict where A and B are classes, and an instance A a (where dict.ContainsKey(a) is true). Is it possible to get the KeyValuePair containing a directly from the Dictionary? Or do I need to create a new KeyValuePair: new KeyValuePair<A, B>(a, dict[a])? ...

Nhibernate will not delete child from collection

First the mapping... <set name="Comments" table="cm_events_venue_comment" inverse="true" lazy="true" generic="true" cascade="all-delete-orphan" batch-size="10" order-by="dateCreated ASC"> <cache usage="read-write" /> <key column="venueId" /> <one-to-many class="VenueComment" /> </set> A passing test.. ...

.NET - What is the best/correct way to iterator through a List and remove misc. members?

In C++ using std::list, this is a simple matter of erasing what an iterator is pointing to (the erase statement returns the next valid member of the list). What's the best way to iterator through a list and remove members that match a certain criteria? ...

Is it possible to save arbitrary data to a file in C#?

I have a class with many collections loaded in memory. Is it possible to some how save this class with all its data to a file to be able to simply reload it to memory later? Is there an interface that would handle all this? ...

Binding collection to tool bar buttons and getting current selected item

Here is the scenario. I'm having a List in my view model and I want to generate a toolbar - each button representing a CustomObject which will have the tooltip, icon etc. I'm defining a template to display CustomObject in a toolbar button and also define the toolbar button ItemSource to the viewmodel collection and ItemTemplate to the o...

convert dictionary.keyscollection to array of strings

i have a Dictionary<string, List<Order>> and i want to have the list of keys in an array. But when i choose string[] keys = dictionary.Keys; this doesn't compile. how do i convert KeysCollection to array of strings. ...

Design pattern for filtering a collection of items?

Imagine the typical type of application where you have a list of items with different properties. E.g. a tree-view with 100 items, each having a name, a rating, a rank-within-the-hottest-items-on-the-planet etc. Probably there are also many-to-many relationships between items and item-catalogs, or between items and item-creators etc etc....

To check if an object is empty or not

Hi friends, I want to check in my function if a passed argument of type object is empty or not. Sometimes it is empty but still not null thus I can not rely on null condition. Is there some property like 'length'/'size' for flex objects which I can use here. Please help. Thanks in advance. ...

Exposing collection through interface

I am new to C#.I wish to know the differences of using Collections. I suspect ,the following question may be asked before(If so kindly show me the link). What is the Difference between IList<int> intCollection = new List<int>(); and List<int> intCollection = new List<int>(); Why should i expose my collection through interface. I...

Why is there no Dictionary.TrimExcess()?

In .NET, there is a constructor for Dictionary<TKey, TValue> that takes one parameter, int capacity. This is the same as with many other collections such as List<T>, Queue<T>, and Stack<T>; furthermore, according to the MSDN documentation: The capacity of a Dictionary is the number of elements that can be added to the Dictionary befo...