C#C
C#3y ago
jseb

List output with Console.Write

Hello, i try to output a Fibonacci list with ';' as separator. I don't want ';' after the last item, so i make it in a quite complicated way.
var fb = new List<int> {1, 1};

for (int i=0; i<10; i++) {
    fb.Add(fb[i]+fb[i+1]);
}

foreach(var n in fb) {
    var sep="; ";
    if (n==fb[fb.Count-1]) { sep=""; }
    Console.Write($"{n}{sep}");
}

any suggestions, please ?
Was this page helpful?