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

If you mean the list of installed applications that is shown in Add\Remove Programs in the control panel, you can find it in the registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall more info about how the registry tree is structured can be found here. You need to use the winreg API in python to read the values from the … Read more

Do C++ enums Start at 0?

Per that standard [dcl.enum] The enumeration type declared with an enum-key of only enum is an unscoped enumeration, and its enumerators are unscoped enumerators. The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators. The optional identifier … Read more

IEnumerable as return type

This is really a two part question. 1) Is there inherently anything wrong with returning an IEnumerable<T> No nothing at all. In fact if you are using C# iterators this is the expected behavior. Converting it to a List<T> or another collection class pre-emptively is not a good idea. Doing so is making an assumption … Read more

Methods inside enum in C#

You can write extension methods for enum types: enum Stuff { Thing1, Thing2 } static class StuffMethods { public static String GetString(this Stuff s1) { switch (s1) { case Stuff.Thing1: return “Yeah!”; case Stuff.Thing2: return “Okay!”; default: return “What?!”; } } } class Program { static void Main(string[] args) { Stuff thing = Stuff.Thing1; String … Read more

for each loop in Objective-C for accessing NSMutable dictionary

for (NSString* key in xyz) { id value = xyz[key]; // do stuff } This works for every class that conforms to the NSFastEnumeration protocol (available on 10.5+ and iOS), though NSDictionary is one of the few collections which lets you enumerate keys instead of values. I suggest you read about fast enumeration in the … Read more

Difference between Java Enumeration and Iterator

Looking at the Java API Specification for the Iterator interface, there is an explanation of the differences between Enumeration: Iterators differ from enumerations in two ways: Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. Method names have been improved. The bottom line is, both Enumeration and … Read more

Collection was modified; enumeration operation may not execute – why?

From the IEnumerable documentation: An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined. I believe the reasoning for this decision is that it cannot be guaranteed that all types … Read more

Enumerations: Why? When?

These are the main arguments for enum, EnumMap, and EnumSet by short examples. The case for enum As of Java 6, java.util.Calendar is an example of a messy class that could’ve benefited a lot from using enum (among other improvements). Currently Calendar defines the following constants (among many others): // int constant antipattern from java.util.Calendar … Read more