jseb
jseb
CC#
Created by jseb on 2/9/2023 in #help
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}");
}
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 ?
6 replies