enumeration

C# loop - break vs. continue

In a C# (feel free to answer for other languages) loop, what's the difference between break and continue as a means to leave the structure of the loop, and go to the next iteration? Example: foreach (DataRow row in myTable.Rows){ if (someConditionEvalsToTrue) { break; //what's the difference between this and continue ? ...

Why aren't Enumerations Iterable?

In Java 5 and above you have the foreach loop, which works magically on anything that implements Iterable: for (Object o : list) { doStuff(o); } However, Enumerable still does not implement Iterable, meaning that do iterate over an Enumeration you must do the following: for(; e.hasMoreElements() ;) { doStuff(e.getNextElement()); ...

PropertyGrid, DefaultValueAttribute, dynamic object, and enumerations

Note: I am using .Net 1.1, although I am not completely against answer that use higher versions. I am displaying some dynamically generated objects in a PropertyGrid. These objects have numeric, text, and enumeration properties. Currently I am having issues setting the default value for the enumerations so that they don't always appear ...

eliminating duplicate Enum code

Hi, I have a large number of Enums that implement this interface: /** * Interface for an enumeration, each element of which can be uniquely identified by it's code */ public interface CodableEnum { /** * Get the element with a particular code * @param code * @return */ public CodableEnum getByCode(String ...

C#: How to enumerate an enum?

How can you enumerate a enum in C#? e.g. the following does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { foreach (Suit suit in Suit) { DoSomething(suit); } } It gives the compile time error: 'Suit' is a 'type' but is used like a 'variable' It fails on the Sui...

Are booleans as method arguments unacceptable?

A colleague of mine states that booleans as method arguments are not acceptable. They shall be replaced by enumerations. At first I did not see any benefit, but he gave me an example. What's easier to understand? file.writeData( data, true ); Or enum WriteMode { Append, Overwrite }; file.writeData( data, Append ); Now I got i...

How to add custom item to system menu in C++?

I need to enumerate all running applications. In particular, all top windows. And for every window I need to add my custom item to the system menu of that window. How can I accomplish that in C++? Update. I would be more than happy to have a solution for Windows, MacOS, and Ubuntu (though, I'm not sure if MacOS and Ubuntu have such th...

Is there a way to iterate through all enum values?

Hi! The subject says all. I want to use that to add the values of an enum in a combobox. Thanks vIceBerg ...

How do you map enums to and from the database using NHibernate?

Edit: Ryan raised a good point. I specifically want to be able to map to and from while still storing human-readable values in the database. That is, I don't want a bunch of enumeration integers in my database. ...

How can I use C# style enumerations in Ruby?

I just want to know the best way to emulate a C# style enumeration in Ruby. ...

What's the best way to iterate through columns of a matrix in MATLAB?

I want to apply a function to all columns in a matrix with MATLAB. For example, I'd like to be able to call smooth on every column of a matrix, instead of having smooth treat the matrix as a vector (which is the default behaviour if you call smooth(matrix)). I'm sure there must be a more idiomatic way to do this, but I can't find it, so...

Which Typesafe Enum in C++ Are You Using?

It is common knowledge that built-in enums in C++ are not typesafe. I was wondering which classes implementing typesafe enums are used out there... I myself use the following "bicycle", but it is somewhat verbose and limited: typesafeenum.h: struct TypesafeEnum { // Construction: public: TypesafeEnum(): id (next_id++), name("") {} ...

Java extendable enumeration

Is there a way to write an enumeration that can be extended. I have several methods that I would like to alway have available for my enumerations. For example I use an enumeration for my database fields. I include the actual field name in the database. public enum ORDERFIELDS { OrderID("Order_ID"); private String...

What dotnet collection class's items can be enumerated in "addition order" and retrieved via a key?

I'm lead to believe that I cannot count on the order of items added to a dictionary for enumeration purposes. Is there a class (generic if possible) to which items may be added with a key and which can be enumerated in addition order or which can be retrieved by key? Clarification: I do not want to enumerate in Key Order. I want to enu...

foreach vs someList.Foreach(){}

There are apparently many ways to iterate over a collection. Curious if there are any differences, or why you'd use one way over the other. First type: List<string> someList = <some way to init> foreach(string s in someList) { <process the string> } Other Way: List<string> someList = <some way to init> someList.ForEach(delegate(s...

How do I create a reusable "US State" type in an XML schema?

I have an XML schema that includes multiple addresses: <xs:element name="personal_address" maxOccurs="1"> <!-- address fields go here --> </xs:element> <xs:element name="business_address" maxOccurs="1"> <!-- address fields go here --> </xs:element> Within each address element, I include a "US State" enumeration: <xs:simpleType na...

How to convert string result of enum with overridden toString() back to enum?

Given the following java enum: public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; } }, A30TO35 { public String toString() { return "30 - 35"; } }, } Is th...

PHP and Enums

I know that PHP doesn't have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which IDEs' auto completion features could understand. Constants do the trick, but there's the namespace collision problem and (or actually because) they're global. Arra...

What is the best way to handle constants in Ruby when using Rails?

I have some constants that represent the valid options in one of my model's fields. What's the best way to handle these constants in Ruby? ...

Enumeration extension methods

In vs2008, is it possible to write an extension methods which would apply to any enumeration. I know you can write extension methods against a specific enumeration, but I want to be able to every enumeration using a single extension method. Is this possible? ...