mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 15:24:09 +03:00
added an example for the foreach loop in C#
This commit is contained in:
parent
10bb7dbce4
commit
758cd94b33
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user