collections

Most efficient way to store a mixed collection of doubles and ints

I need to store a collection of ints and doubles (representing nominal and real valued data) in c++. I could obviously store them all in a std::vector<double> , but this feels a bit wrong and doesn't get the aesthetics bonus points. I could also cook up something based on polymorphism, but I also need the collection to be really efficie...

Having trouble binding list/grid to collection

I have set up a grid and bound it to a collection. I can edit the items in the collection through my grid and the changes get propagated to the collection. And, the GUI is showing everything in the collection at the time the ItemSource is set. But, I am programmatically changing some of the items in the collection (after the ItemSourc...

Is this code sample really returning the right parameterized types?

I've read the Beautiful code with Google Collections, Guava and static imports article about Java collections, and the following snippet got my attention: Map<String, Map<Long, List<String>>> map = Maps.newHashMap(); The thing is, I don't understand how it's possible that the newHashMap method can return a Map<String,Map<Long, List<St...

Java-like Collections in PHP

I'm learning PHP5 (last time I checked PHP was in PHP4 days) and I'm glad to see that PHP5 OO is more Java-alike than the PHP4 one but there's still an issue that makes me feel quite unconfortable because of my Java background : ARRAYS. I'm reading "Proffesional PHP6" (Wrox) and It shows its own Collection implementation. I've found ot...

NHIBERNATE: How to map a collection into the DB using Mapping.Attributes

I Have this Product Class i took from the examples of how to use nhibernate (but i did some modifications to it) I want to be able to map a class and all of it's references into the DB. [NHibernate.Mapping.Attributes.Class(Lazy=true)] public class Product { [NHibernate.Mapping.Attributes.Id(Name="Id",TypeTyp...

Can you insert at position 0 in a List<MyObject> ?

I need to insert an object at the beginning of a collection. My colleciton is of type List How can I do this? ...

ASP.Net - Displaying a collection of controls

I am creating a simple form. I have created two simple classes, Question and QuestionSection. I then create some subclasses of question, e.g. SimpleQuestion, MultipleChoiceQuestion, with different behaviour and markup. QuestionSection has a property of a collection of questions, like so- private List<Question> _Questions = new List<Qu...

lazy loaded NHibernate collections into ViewModels?

hey folks, I have my NHibernate mappings set to lazy loading = true. In my CustomersViewModel I have something like: foreach (Customer c in _customerRepository) { this.Customers.Add(new SingleCustomerViewModel(c)); } This obviously kills all the lazy loading, since the customers are passed one by o...

Are Hashtable objects still useful?

Has the System.Collections.Hashtable object become obsolete? With the implementation and refinements in generics from C# v2 and v3, it's been a long time since I've found a Hashtable more appropriate than a generic Dictionary. Literally, I can't recall the last time I used Hashtable. Just wondering if anyone else has found a case where...

How do I inherit from Dictionary?

I want all the functionality of Dictionary<TKey,TValue> but I want it as Foo<TKey,TValue>. How should I go about doing this? Currently I am using class Foo<TKey,TValue> : Dictionary<TKey, TValue> { /* I'm getting all sorts of errors because I don't know how to overload the constructors of the parent class. */ ...

Changing the BackColor of my custom UserControl - help!

Hello my kind sirs. (lol) I have a panel on Form1. I'm going to add several instances of my custom usercontrol MovieItem to that panel. To do this I'm going: panel1.Controls.Add(objMovieItem); Now, within the MovieItem.cs code I'm adding the .Click events of everything inside the UserControl so that whenever a user clicks ANYWHERE i...

Point of need of custom Enumerations

When reading a post some points were given without example : To implement IEnumerable / IEnumerable, you must provide an enumerator : •If the class is "wrapping" another collection, by returning the wrapped collection's enumerator. •Via an iterator using yield return. •By instantiating your own IEnumerator/IEnumerator implementatio...

Irregularities when adding controls to my panel. They show up whever they want!

Here's my code: int ypos = 0; public void X() { MovieItem NewMovie = new MovieItem(); NewMovie.SearchMovie(txtSearch.Text); NewMovie.Location = new Point(0, ypos); ypos += 196; panel1.Controls.Add(NewMovie); } After running method X about 4,5 times, the 5th or 6th item added isn't added where it should instead it...

How to create a enumerator/generator of strings or integers?

I want to have a enumerator/generator that will always provide me with the next value whenever I call say GetNext? Is this possible? Examples: myStringEnumerator.GetNext() -> returns "Identifier01.xml" myStringEnumerator.GetNext() -> returns "Identifier02.xml" myStringEnumerator.GetNext() -> returns "Identifier03.xml" myStringEnu...

Calculating frequency distribution of a collection with .Net/C#

Is there a fast/simple way to calculate the frequency distribution of a .Net collection using Linq or otherwise? For example: An arbitrarily long List contains many repetitions. What's a clever way of walking the list and counting/tracking repetitions? ...

ASP.NET which type of collection should I use?

I am writing a class to save searches on my site. I want to have in the class an "Array" of all the parameters that were specified. I tried a NameValueCollection but the problem I ran into is when I have a multi-select (e.g. states) it only stores one of the entries because the key gets taken. I need a collection type that will let me ha...

Transpose a Collection

Hello, I've a list of different sizes of a T-Shirt, e.g. S, M, L. Since this might change for T-Shirts (sometimes we just have e.g. M, L), we load this into a List sizes. Since most DataGrids (xamDataGrid, WPF Toolkit DataGrid) need Properties for binding to the Columns, I'd like to transpose somehow my data. Does anyone have an idea h...

How to avoid unchecked casts in overriden Collection's methods?

I'm working on a List implementation. Because of this, I'll have to override the methods Collection.containsAll(Collection<?> c); Collection.removeAll(Collection<?> c); Collection.retainAll(Collection<?> c); But as it's explained by Sun, they accept collections with any kind of content (note the <?>). So the collection is not checked ...

Custom collection and enumeration ASP.NET/C#

Why do we need custom collection and custom enumeration by implementing IEnumerable and IEnumerator ( I Know what IEnumerable and IEnumerator does and how to implement them).The Question is as anything can be done with collections like Dictionary,Hashtable,List ,do we use custom enumeration to make non-enumerable items to enumerable co...

can i have an ordered dictionary by date

i have a dictionary where the key is a date and the value is an object. is there anyway i can ensure that when i loop through this collection its in chronological order always even after adding and deleting items. ...