C
C#4mo 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
Jimmacle4mo ago
you aren't using Console.WriteLine correctly you should be building your whole string using string interpolation, not just the count part
js
js4mo ago
Console.WriteLine($"{count1}. {Path.GetFileName(file)}"); is that better
Jimmacle
Jimmacle4mo ago
try it
js
js4mo ago
yh it works thanks
Waffles from Human Resources
Also you can just use count1++; to increment by 1
Want results from more Discord servers?
Add your server
More Posts
.HasPrincipalKey -> Specify different column nameI need to use `.HasPrincipalKey` in Fluent, but I need the resulting column to be named differently WPF mousePos and icon.Margin align. Visual rep does not.So I'm trying to make an icon visible in a map at the same position as the mouseclick, but it alwaysHow do I refresh view data from inside of a view?I have a SignalR setup, and I have it where when I press on a button, it will send a message to the ✅ Why is an explicit cast needed even though the implicit cast operator is available?No explicit cast is needed. ```csharp var (x, y) = GetPoint(); static (float re, float im) GetPoint(Need help in getting my dice to hold and release in a yahtzee type game.I am having issues with being able to hold and release dice in a yahtzee game. This was working, buTrying to read from a binary fileNew to c#, trying to validate a username and password from a binary file, but getting the issue 'TooHow to pass a Type to a method for a return of the same typeStruggling to find the right syntax for this. I'm trying to specify a type that should be used to crmathim brand new to C# and Im making a wage calculator but the math is wrong, it keeps rounding the outpSystem.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: APostmanden has an API written with the GET method that we can access from the browser without any prArray exceptionI can't for the life of me figure out this exception. ive identified that it comes from neurons beca