using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ForEach_GL { class Program { static void Main(string[] args) { //Array mit 3 Büchern befüllen ==> Variante 1 string[] aMyBooks = new string[3];
aMyBooks[0] = "Harry Potter 1"; aMyBooks[1] = "Iluminati"; aMyBooks[2] = "Visual C# 2008";
//Array mit 3 Büchern befüllen ==> Variante 2 string[] aMyBooks_2 = new string[]{ "Harry Potter 1", "Iluminati", "Visual C# 2008"};
//mittels For Schleife die Daten ausgeben Console.WriteLine("Es stehen folgende Bücher im Array: ==> FOR SCHLEIFE "); for (int i = 0; i < aMyBooks.Length; i++) { Console.WriteLine("\t{0}", aMyBooks[i]); }
Console.WriteLine(""); Console.WriteLine(""); //mittels der ForEach Schleife die Daten ausgeben //Jeder Titel des Arrays wird in die Variable sTitel kopiert und ausgegeben //die Variable sTitel kann NICHT verändert werden Console.WriteLine("Es stehen folgende Bücher im Array: ==> FOREACH SCHLEIFE "); foreach (string sTitel in aMyBooks) { Console.WriteLine("\t{0}", sTitel); }
Console.WriteLine(""); } } } zurück zur vorherigen Seite  |