C
C#10mo ago
js

problem with console writeline

Console.WriteLine("Please select a file to load.");

string[] filePaths = Directory.GetFiles(@"C:\Users\Joe\Documents\Uni\Programming Portfolio\Summative4\Summative4", "*.mark");

int count1 = 1;

foreach (string file in filePaths)
{
Console.WriteLine($"{count1}. ",Path.GetFileName(file));
count1 = count1 + 1;
}
string selectedFile = Console.ReadLine();
Console.WriteLine("Please select a file to load.");

string[] filePaths = Directory.GetFiles(@"C:\Users\Joe\Documents\Uni\Programming Portfolio\Summative4\Summative4", "*.mark");

int count1 = 1;

foreach (string file in filePaths)
{
Console.WriteLine($"{count1}. ",Path.GetFileName(file));
count1 = count1 + 1;
}
string selectedFile = Console.ReadLine();
when i run the program its printing all the filenames fine but not the number before each file (count1)
No description
5 Replies
Jimmacle
Jimmacle10mo ago
you aren't using Console.WriteLine correctly you should be building your whole string using string interpolation, not just the count part
js
jsOP10mo ago
Console.WriteLine($"{count1}. {Path.GetFileName(file)}"); is that better
Jimmacle
Jimmacle10mo ago
try it
js
jsOP10mo ago
yh it works thanks
The Fog from Human Resources
Also you can just use count1++; to increment by 1
Want results from more Discord servers?
Add your server