enumeration

Is the order in which handles are returned by EnumWindows meaningful?

From a couple of preliminary tests it seems that EnumWindows always returns windows in reverse instantiation order, i.e. most recently instantiated window first. Is that a valid observation? If so, is it true across all versions of Windows? And is this a reliable assumption, i.e. is that behaviour documented somewhere? Context: I'm de...

synch enumeration with static data from a database

Hi I have an enumeration of delivery status codes. And when I save delivery data to the database they are stored with a foreign key to a table containing the same data (i.e. the same delivery codes) What is the best strategy for keeping an enumeration in synch with data in a database? Do you just remember to add to the enumeration wh...

Does this linq query run on every iteration of the for-each loop?

In another question on SO I answered with code like the one below and got a comment that the LINQ-query probably was evaluated in every iteration of the for/each. Is that true? I know that LINQ-querys does not executes before its items is evaluated so it seems possible that this way to iterate the result can make it run on every iterati...

Enumeration management with zend framework (ZF)?

Is there any existing project or incubator to manage user administratable lists of options? We have several 100 lists (most populate dropdowns in our application), many are quite short < 50 items, several with a few hundred items and a handful with thousands (<30,000) entries. What we are looking for is a database based structure and UI...

How can this Linq2Sql create an enum in the select clause?

Hi folks, i've got the following linq2sql query, and i'm setting the result to a POCO. One of my POCO properties is an enumeration. public IQueryable<Models.Achievement> GetAchievements() { return from a in _sqlDatabase.Achievements select new Models.Achievement { // Note: ToEnum is an extension ...

Enumerator Implementation: Use struct or class?

I noticed that List<T> defines its enumerator as a struct, while ArrayList defines its enumerator as a class. What's the difference? If I am to write an enumerator for my class, which one would be preferable? EDIT: My requirements cannot be fulfilled using yield, so I'm implementing an enumerator of my own. That said, I wonder whether i...

What is the tilde (~) in a C# enumeration?

I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about... I've tried searching the internet for this, but using the "~" in a search isn't working for me so well and I didn't find anything on MSDN either (not to say it isn't there) I saw this snippet of code recently, what ...

Enumerate or list all variables in a program of [your favorite language here]

A friend asked me last week how to enumerate or list all variables within a program/function/etc. for the purposes of debugging (essentially getting a snapshot of everything so you can see what variables are set to, or if they are set at all). I looked around a bit and found a relatively good way for Python: #!/usr/bin/python ...

Lookup Tables Best Practices: DB Tables... or Enumerations

If we have to store the available positions at a company (i.e. Manager, Team Lead, ... etc). What are the best practices for storing it? I have two opinions with comments... "sure, welcoming yours" Storing it as DB table with columns ID and Name, and deal with it using queries and joins. Storing it as Enum and forget about the...

Treat a class as if it was defined with an interface

I have a 100 classes that have some similar elements and some unique. I've created an interface that names those similar items eg: interface IAnimal. What i would normally do is: class dog : IAnimal But there are 100 classes and i don't feel like going though them all and looking for the ones that i can apply IAnimal to. What i want ...

How to use std::foreach with parameters/modification

I've found myself writing for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like for(int i=0;i<myvec.size();i++) if(myvec[i]->IsOK()) myvec[i]->DoWhatever(p...

Does GetCustomAttributes() preserve the attribute order in .NET?

The title pretty much says it all. When I'm doing some reflection through my classes, will the MemberInfo.GetCustomAttributes() method preserve the order of attributes on a member, or not? The official documentation does not say anything one way or the other. In case you're wondering why I would need this, here's the full explanation....

C# - The foreach identifier and closures

In the two following snippets, is the first one safe or must you do the second one? By safe I mean is each thread guaranteed to call the method on the Foo from the same loop iteration in which the thread was created? Or must you copy the reference to a new variable "local" to each iteration of the loop? var threads = new List<Thread>(...

Why is the visitor responsible for enumerating children in the visitor pattern?

Based on the code I've found, it seems that the Visitor is required to known the structure of the visited objects and call on the needed children. This seems a bit clunky in some cases where the visitor would want to continue to work even if the visited classes are modified. I guess the real question is: Is their a pattern where the enu...

Objective-C 2.0 and Fast Enumeration throwing exceptions

I have a block of code which is similar to the following: for (NSDictionary *tmp in aCollection) { if ([[bar valueForKey:@"id"] isEqualToString:[tmp valueForKey:@"id"]]) { break; } else { [aCollection addObject:bar]; } } Is this technically an exception in Objective-C 2.0? It appears you cannot mutat...

What is the difference between for..in and for each..in in javascript?

What is the difference between for..in and for each..in statements in javascript? Are there subtle difference that I don't know of or is it the same and every browser has a different name for it? ...

Need to make an enumeration of type double in c#

Hi, How can I create an enum of type double? Is it possible or do I have to create some kind of collection and hash? ...

Dictionary enumeration in c#

Hi, I want to enumerate dictionary. How i enumerate. Thanks ...

Finding Strings Neighbors By Up To 2 Differing Positions

Hi all, Given a seed string, I want to find its neighbors with at most differ in 2 positions. All the digits involve in generating string are only four (i.e. 0,1,2,3). This is the example for what I mean: # In this example, 'first' column # are neighbors with only 1 position differ. # The rest of the columns are 2 positions differ See...

enumerating from an index/value in ruby

So ive got this big-ass collection right? Its tree-backed(RBTree), so look-ups are fast, and the values are sorted. Say ive got value X. I can look up X in my tree in logn time, cool. But I want the values to the right of X in the tree as well, until one of them dosent satisfy a test. Ie, get all elements that are >= X and < Y I could ...