added an example for the foreach loop in C#

This commit is contained in:
Melvyn 2013-09-21 16:07:43 -04:00
parent 10bb7dbce4
commit 758cd94b33

View File

@ -325,6 +325,17 @@ namespace Learning
}
Console.WriteLine("fooFor Value: " + fooFor);
// For Each Loop
// foreach loop structure => foreach(<iteratorType> <iteratorName> in <enumerable>)
// The foreach loop loops over any object implementing IEnumerable or IEnumerable<T>
// All the collection types (Array, List, Dictionary...) in the .Net framework implement one or both of these interfaces
// (The ToCharArray() could be removed, because a string also implements IEnumerable)
foreach (char character in "Hello World".ToCharArray())
{
//Console.WriteLine(character);
//Iterated over all the characters in the string
}
// Switch Case
// A switch works with the byte, short, char, and int data types.
// It also works with enumerated types (discussed in Enum Types),