diff options
author | Melvyn <melvyn.laily@gmail.com> | 2013-09-21 16:07:43 -0400 |
---|---|---|
committer | Melvyn <melvyn.laily@gmail.com> | 2013-09-21 16:07:43 -0400 |
commit | 758cd94b33dcfce89ab308c67725513184fb3c4b (patch) | |
tree | 74c7bd2d201e86c8845d07698fd07da1cb0aef79 | |
parent | 10bb7dbce413be31916c02b340b15f1a4e4a6a23 (diff) |
added an example for the foreach loop in C#
-rw-r--r-- | csharp.html.markdown | 11 |
1 files changed, 11 insertions, 0 deletions
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(<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. |