C
C#5mo ago
Gamer1234556

✅ System.FormatException: 'Input string was not in a correct format.'

Hello, I am trying to make a Winform Program that takes in a text file, turns it into a string in a generated array textbox, and then sorts the array in another textbox called sort values. However, it seems like I am having some issues parsing my string. Can someone help me here? Here is the link to my code: https://paste.mod.gg/aarnffywcwsx/0
BlazeBin - aarnffywcwsx
A tool for sharing your source code with the world!
18 Replies
Pobiega
Pobiega5mo ago
Where exactly is that exception thrown? On the int[] values = Array.ConvertAll(lines, int.Parse);?
Gamer1234556
Gamer12345565mo ago
Yes
Angius
Angius5mo ago
It means one of the values is not a valid integer, then
Gamer1234556
Gamer12345565mo ago
Hmmm that’s not right Should I send my text file or something? Or a screenshot of what’s going on? Gimme a sec, I went to sleep after I posted this so I am just seeing all of this now
Pobiega
Pobiega5mo ago
A bit curious, why would you do that? Why ask for help as you become available, instead of when you are available? Almost always, we will have to ask questions to provide help.
Gamer1234556
Gamer12345565mo ago
Because from my experience it takes a while in order to actually get help And sometimes the time zones can be very different whenever I ask questions Whenever I ask these questions it could be in the middle of the night And I haven’t gotten actual sleep cuz I have been going at a problem so too many hours on my own
Pobiega
Pobiega5mo ago
I'd say 80-90% of well asked questions get some form of interaction within 30 minutes or so anyways, show the file
Gamer1234556
Gamer12345565mo ago
Ok gimme a sec
Pobiega
Pobiega5mo ago
ok see look at your code
// Read all lines from the text file
string[] lines = File.ReadAllLines(fname);

// Convert lines to integers
int[] values = Array.ConvertAll(lines, int.Parse);
// Read all lines from the text file
string[] lines = File.ReadAllLines(fname);

// Convert lines to integers
int[] values = Array.ConvertAll(lines, int.Parse);
so we read all lines into an array then pass each of those lines to int.Parse how many lines do you have in that file there?
Gamer1234556
Gamer12345565mo ago
Only one
Pobiega
Pobiega5mo ago
mhm and is , a valid integer number?
Gamer1234556
Gamer12345565mo ago
No
Pobiega
Pobiega5mo ago
so.. can you see the issue now? 🙂
Gamer1234556
Gamer12345565mo ago
Yeah I sort of do I will see what I can do
Angius
Angius5mo ago
Hint: .Split()
Pobiega
Pobiega5mo ago
and File.ReadAllText
Gamer1234556
Gamer12345565mo ago
Ok I fixed the problem. Thanks