Lord_X
2008-07-29, 14:23:48
Hallo :)
Ich habe dieses Beispiel gesehen:
using System;
using System.Collections.Generic;
using System.Text;
namespace test3
{
class Program
{
static void Main(string[] args)
{
int[] liste = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (long zahl in liste)
{
Console.WriteLine(zahl);
}
}
}
}
Das klappt alles wie es soll. Er gibt mir alle Zahlen aus.
Jetzt wollte ich aber anstelle von Zahlen Wörter ausgeben. Also habe ich das wie folgt umgeschrieben:
using System;
using System.Collections.Generic;
using System.Text;
namespace test3
{
class Program
{
static void Main(string[] args)
{
string[] listeprog = new string[] { prog1, prog2 };
foreach (string wort in listeprog)
{
Console.WriteLine(wort);
}
}
}
}
Wieso geht das so nicht? (Bin Anfänger)
Ich habe dann eine Lösung gefunden aber mich würde trotzdem interessieren, warum es bei meinem ersten Versuch nicht geklappt hat.
string[] listeprog = new string[2];
listeprog[0] = "prog1";
listeprog[1] = "prog2";
foreach (string wort in listeprog)
{
Console.WriteLine(wort);
}
Danke
Lord_x
Ich habe dieses Beispiel gesehen:
using System;
using System.Collections.Generic;
using System.Text;
namespace test3
{
class Program
{
static void Main(string[] args)
{
int[] liste = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (long zahl in liste)
{
Console.WriteLine(zahl);
}
}
}
}
Das klappt alles wie es soll. Er gibt mir alle Zahlen aus.
Jetzt wollte ich aber anstelle von Zahlen Wörter ausgeben. Also habe ich das wie folgt umgeschrieben:
using System;
using System.Collections.Generic;
using System.Text;
namespace test3
{
class Program
{
static void Main(string[] args)
{
string[] listeprog = new string[] { prog1, prog2 };
foreach (string wort in listeprog)
{
Console.WriteLine(wort);
}
}
}
}
Wieso geht das so nicht? (Bin Anfänger)
Ich habe dann eine Lösung gefunden aber mich würde trotzdem interessieren, warum es bei meinem ersten Versuch nicht geklappt hat.
string[] listeprog = new string[2];
listeprog[0] = "prog1";
listeprog[1] = "prog2";
foreach (string wort in listeprog)
{
Console.WriteLine(wort);
}
Danke
Lord_x