summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMelvyn <melvyn.laily@gmail.com>2013-09-21 16:07:43 -0400
committerMelvyn <melvyn.laily@gmail.com>2013-09-21 16:07:43 -0400
commit758cd94b33dcfce89ab308c67725513184fb3c4b (patch)
tree74c7bd2d201e86c8845d07698fd07da1cb0aef79
parent10bb7dbce413be31916c02b340b15f1a4e4a6a23 (diff)
added an example for the foreach loop in C#
-rw-r--r--csharp.html.markdown11
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.