The foreach keyword

C# iterators use foreach instead of for. Also, notice the variable declaration within the for/foreach statement. C# requires the type of the item contained in the list to be explicitly declared.

JavaScript:

for (var item in itemList) {
  item.DoSomething();
}

C#:

foreach (ItemType item in itemList) {
  item.DoSomething();
}

Note

Although the JavaScript version uses inefficient dynamic typing (since you can't declare the type), the static-typed alternative is as follows.

JavaScript:

for (var item = itemList.GetEnumerator(); item.MoveNext();) {
  item.DoSomething();
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.164.75