public static void Formatme()
{
string[] test = new string[4];
test[1] = "AA";
test[2] = "BB";
test[3] = "CC";
test[0] = "DD";
/*I like to do things in good ways. Now I need to iterate through the array so it looks like this:
1. "AA"
2. "BB"
etc ..*/
//sln using .net core 6
var result = test.Select((s, i) => $"{i + 1}. {s}").ToArray();
foreach (var item in result)//even if you dont do ToArray it will be IEnumerable
{
Console.Write(item);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter