mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-17 12:10:52 +02:00
added an example for the foreach loop in C#
This commit is contained in:
@@ -325,6 +325,17 @@ namespace Learning
|
|||||||
}
|
}
|
||||||
Console.WriteLine("fooFor Value: " + fooFor);
|
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
|
// Switch Case
|
||||||
// A switch works with the byte, short, char, and int data types.
|
// A switch works with the byte, short, char, and int data types.
|
||||||
// It also works with enumerated types (discussed in Enum Types),
|
// It also works with enumerated types (discussed in Enum Types),
|
||||||
|
Reference in New Issue
Block a user