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(string s) { … Read more

for each loop in Objective-C for accessing NSMutable dictionary

I am finding some difficulty in accessing mutable dictionary keys and values in Objective-C. Suppose I have this: NSMutableDictionary *xyz=[[NSMutableDictionary alloc] init]; I can set keys and values. Now, I just want to access each key and value, but I don’t know the number of keys set. In PHP it is very easy, something as … Read more

Enumerations on PHP

I know that PHP doesn’t yet 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. … Read more

How to enumerate an enum

How can you enumerate an enum in C#? E.g. the following code does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { foreach (Suit suit in Suit) { DoSomething(suit); } } And it gives the following compile-time error: ‘Suit’ is a ‘type’ but is used like a ‘variable’ It … Read more