From 758cd94b33dcfce89ab308c67725513184fb3c4b Mon Sep 17 00:00:00 2001 From: Melvyn Date: Sat, 21 Sep 2013 16:07:43 -0400 Subject: added an example for the foreach loop in C# --- csharp.html.markdown | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/csharp.html.markdown b/csharp.html.markdown index 0c459bdb..e6a174c3 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -324,6 +324,17 @@ namespace Learning //Iterated 10 times, fooFor 0->9 } Console.WriteLine("fooFor Value: " + fooFor); + + // For Each Loop + // foreach loop structure => foreach( in ) + // The foreach loop loops over any object implementing IEnumerable or IEnumerable + // 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. -- cgit v1.2.3