collections

IEnumerable<T>.Concat -- A replacement that can work without changing the reference?

Hello, I've recently been bitten by the (way too commmon in my opinion) gotcha of Concat returns it's result, rather than appending to the list itself. For instance. List<Control> mylist=new List<Control>; //.... after adding Controls into mylist MyPanel.Controls.Concat(mylist); //This will not affect MyPanel.Controls at all. MyPane...

Can I have a set containing identical elements?

It is convenient for me to use a set. I like how I can "add" ("remove") an element to (from) the set. It is also convenient to check if a given element is in the set. The only problem, I found out that I cannot add a new element to a set if the set has already such an element. Is it possible to have "sets" which can contain several iden...

How do I implement a collection in Scala 2.8?

In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1). Basically what I need is to write something that: adds functionality to immutable sets of a certain type where all methods like filter and map return a collection of the same type without having to override everything (which is why I went for 2.8 in th...

Why does a HashMap rehash the hashcode supplied by the Key object

I am reading up the code of the HashMap class provided by the java 1.6 API and unable to fully understand the need of the following operation (found in the body of put and get methods) : int hash = hash(key.hashCode()); where the method hash() has the following body: private static int hash(int h) { h ^= (h >>> 20) ^ (h >>>...

Tiered Design With Analytical Widgets - Is This Code Smell?

The idea I'm playing with right now is having a multi-leveled "tier" system of analytical objects which perform a certain computation on a common object and then create a new set of analytical objects depending on their outcome. The newly created analytical objects will then get their own turn to run and optionally create more analytical...

Is there a way to transfrom a list of key/value pairs into a data transfer object

...apart from the obvious looping through the list and a dirty great case statement! I've turned over a few Linq queries in my head but nothing seems to get anywhere close. Here's the an example DTO if it helps: class ClientCompany { public string Title { get; private set; } public string Forenames { get; private s...

silverlight with WCF(get data through collections)

in my silverlight page I am fetching the data through WCF WCF is returning an BusinessEntityCollection that is the collection of rows SqlParameter[] sqlParameter = new SqlParameter[]{new SqlParameter("@recordType",recordType)}; MenuEntity menuEntity; MenuEntityCollection menuEntityCollection = new MenuEnt...

Re-ordering collection C#

Hi - I have a problem which I cant seem to find answer to through searches (either that or I am searching for the completely wrong thing!). I have a list of items called "Top 10" in a sortedlist item that is populated from my DB (SortedList where int is position and string is item). I want to be able to move items up & down the list or...

Database access through collections

Hi All, I have an 3 tiered application where I need to get database results and populated the UI. I have a MessagesCollection class that deals with messages. I load my user from the database. On the instantiation of a user (ie. new User()), a MessageCollection Messages = new MessageCollection(this) is performed. Message collection accep...

Hibernate Collection chaining

I have two Entities University courses Course students i want to access all the students in a university. I tried the following query select u.courses.students from university u i got the following exception. org.hibernate.QueryException: illegal attempt to dereference collection [university0_.id.courses] with element p...

Binding List to DataGrid Silverlight

Hi, I have a problem binding List to a DataGrid element. I've created a class that implements INotifyPropertyChange and keeps list of orders: public class Order : INotifyPropertyChanged { private String customerName; public String CustomerName { get { return customerName; } set { customerN...

nhibernate mapping: delete collection, insert new collection with old IDs

my issue lokks similar to this one: (link) but i have one-to-many association: <set name="Fields" cascade="all-delete-orphan" lazy="false" inverse="true"> <key column="[TEMPLATE_ID]"></key> <one-to-many class="MyNamespace.Field, MyLibrary"/> </set> (i also tried to use ) this mapping is for Template object. this one and the Field...

In .NET, will cleaning a nested dictionaries parent release all memory upon garbage collection?

I have the following nested dictionaries: Dictionary<int, Dictionary<string, object>> x; Dictionary<int, SortedDictionary<long, Dictionary<string, object>>> y; If I do x.Clear() and y.Clear() will all the nested objects clear and all the memory will be reused on the next garbage collection? Or do I need to iterate on all the items ...

How to load entities into private collections using the entity framework

I have a POCO domain model which is wired up to the entity framework using the new ObjectContext class. public class Product { private ICollection<Photo> _photos; public Product() { _photos = new Collection<Photo>(); } public int Id { get; set; } public string Na...

How to give a custom ASP.NET control the ability to parse XML markup to a collection?

I'm writing a custom ASP.NET webcontrol and would like it to have a collection of custom items which can also be specified in the XML markup. Something like this: class MyControl: WebControl { public IList<MyItemType> MyItems { get; private set; } } And in the markup: <asd:MyControl runat="server" id="mc1"> <MyItems> ...

C# Property Access vs Interface Implementation

I'm writing a class to represent a Pivot Collection, the root object recognized by Pivot. A Collection has several attributes, a list of facet categories (each represented by a FacetCategory object) and a list of items (each represented by a PivotItem object). Therefore, an extremely simplified Collection reads: public class PivotCollec...

Hashtable is that fast

Hi s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]. Is the hash function of the java string, I assume the rest of languages is similar or close to this implementation. If we have hash-Table and a list of 50 elements. each element is 7 chars ABCDEF1, ABCDEF2, ABCDEF3..... ABCDEFn If each bucket of hashtable contains 5 strings (I think th...

What is the complexity of OrderedDictionary?

Hi No one said that OrderedDictionary is having two copies of elements, one in a hashtable and other in a list, I can't find complexity measurements at MSDN for OrderedList. thanks ...

Transient collections for Scala?

Clojure has a very nice concept of transient collections. Is there a library providing those for Scala (or F#)? ...

Is there an equivalent for ActiveRecord#find_by equivalent for C#?

I'm originally a C# developer (as a hobby), but as of late I have been digging into Ruby on Rails and really enjoying it. Right now I am building an application in C#, and I was wondering if there is any collection implementation for C# that could match (or "semi-match") the find_by method of ActiveRecord. What I am essentially looking ...