Java vs. C#

foreach


Java
 
Start from Java 5, Java has for each feature
Collection c
for (Object o : c){
 
      
}

The above is equivalent to for (Iterator i = c.iterator(); i.hasNext(); ) { }
If you don't use Java 5, use the following to replace C# foreach statement. while (! collection.isEmpty()) { Object o = collection.get(); collection.next(); ... }
for (int i = 0; i < array.length; i++){ ... }

C#
 
foreach statement is a short-hand of for statement
Readonly feature
foreach (object o in collection){


}

foreach (int i in array){ }