enumeration

Distinction between iterator and enumerator

An interview question for a .NET 3.5 job is "What is the difference between an iterator and an enumerator"? This is a core distinction to make, what with LINQ, etc. Anyway, what is the difference? I can't seem to find a solid definition on the net. Make no mistake, I can find the meaning of the two terms but I get slightly different an...

casting an enumeration to get the value associated with it?

I have an enum like: public enum BlahType { blahA = 1, blahB = 2, blahC = 3 } if I have a string with the value 'blahB', is it possible to cast it against the enum BlahType to get the value 2? ...

for each loop iteration

Let us assume the code I use to iterate through a node list foreach(XmlNode nodeP in node.SelectNodes("Property")) { propsList.Add(nodeP.Attributes["name"].Value, true); } in this case does the expression node.SelectNodes("Property") , get evaluated during each iteration of for each or once? ...

What is the best way to modify a list in a foreach?

Hello, a new feature in C# / .NET 4.0 is that you can change your enumerable in a foreach without getting the exception. See Paul Jackson's blog for info on this change. So I'm asking: what is the best way to do this: foreach(var item in Enumerable) { foreach(var item2 in item.Enumerable) { item.Add(new item2) } } ...

Extract enumeration values from xsd schema file in .net

How programmatically extract enumeration constraint values of an element from xsd schema file using .net? for example I'd like to extract 'Audi', 'Golf' and 'BMW' from the following xsd: <xs:element name="car"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi"/> <xs:enumeration value="Golf...

How can I enumerate/list all installed applications in Windows XP?

When I say "installed application", I basically mean any application visible in [Control Panel]->[Add/Remove Programs]. I would prefer to do it in Python, but C or C++ is also fine. ...

What is the best way to convert an IEnumerator to a generic IEnumerator?

I am writing a custom ConfigurationElementCollection for a custom ConfigurationHandler in C#.NET 3.5 and I am wanting to expose the IEnumerator as a generic IEnumerator. What would be the best way to achieve this? I am currently using the code: public new IEnumerator<GenericObject> GetEnumerator() { var list = new List(); var bas...

Strange "Collection was modified after the enumerator was instantiated" exception

Perhaps someone can point me in the correct direction, because i'm completely stumped on this. I have a function that simply prints out a LinkedList of classes: LinkedList<Component> components = new LinkedList<Component>(); ... private void PrintComponentList() { Console.WriteLine("---Component List: " + compon...

Populate an enum with values from database

I have a table which maps String->Integer. Rather than create an enum statically, I want to populate the enum with values from a database. Is this possible ? So, rather than delcaring this statically: public enum Size { SMALL(0), MEDIUM(1), LARGE(2), SUPERSIZE(3) }; I want to create this enum dynamically since the numbers {0,1,2,3} ...

Dynamically enumerating values for a property in .Net

You know how a TreeView control's ImageList property lists all ImageLists on a form? I need something similar, but with a list of strings. It's like an enumeration, but defined at runtime, with the object that exposes the property in a PropertyGrid. So, with a list of strings like { "foo", "bar", "grill" } the property should list those...

Enumerate substitutions with sed or awk

Given the plain text file with lines bli foo bla abc dfg bli foo bla hik lmn what sed or awk magic transforms it to bli foo_01 bla abc dfg bli foo_02 bla hik lmn so that every occurence of 'foo' is replaced by 'foo_[occurence number]'. ...

Enumerate through a subset of a Collection in C#?

Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements 250 - 340. Is there a good way to get an Enumerator for a subset of the collection, without using another Collection? Edit: should have men...

Enumerate members of a structure?

Is there a way to enumerate the members of a structure (struct | class) in C++ or C? I need to get the member name, type, and value. I've used the following sample code before on a small project where the variables were globally scoped. The problem I have now is that a set of values need to be copied from the GUI to an object, file, a...

Is there a predefined enumeration for Month in the .NET library?

I'm looking to see if there is an official enumeration for months in the .net framework. It seems possible to me that there is one, because of how common the use of month is, and because there are other such enumerations in the .net framework. For instance, there is an enumeration for the days in the week, System.DayOfWeek, which inclu...

Why do people use enums in C++ as constants while they can use const?

Hello. I was just wondering why people use enums in C++ as constants while they can use const. Thanks ...

Working with the ObjectQuery Single Enumeration Challenge in Linq-To-Entities Entity SQL

I'm working on modifying this example: Using advWorksContext As New AdventureWorksEntities ' Call the constructor that takes a command string and ObjectContext. Dim productQuery1 As New ObjectQuery(Of Product)("Product", advWorksContext) Dim result As Product For Each result In productQuery1 Console.WriteLine("P...

different using. java.util.Enumeration and Iterator

what is the exact different of both.. is using enumeration more benefit than using iterator..? can anyone elaborate.. any reference article would be appeciated ...

How to enumerate a list of non-string objects in Python?

There is a nice class Enum from enum, but it only works for strings. I'm currently using: for index in range(len(objects)): # do something with index and objects[index] I guess it's not the optimal solution due to the premature use of len. How is it possible to do it more efficiently? ...

How do I iterate over an NSArray?

I'm looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+. ...

Enumeration of combinations of N balls in A boxes?

Hi, I want to enumerate all possible combinations of N balls in A boxes. example: I have 8 balls to deal in 3 boxes : box_1 box_2 box_3 case-1 8 0 0 case-2 0 8 0 case-3 0 0 8 case-4 7 1 0 case-5 7 0 1 case-6 6 2 0 ...