C
C#2mo ago
Gingy

learning C#

having trouble with a simple code asking for name and age and the app should output it but doesnt seem to be working any help is greatly appreciated namespace collectNameAgeApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string name = textBox1.Text; int age; if (int.TryParse(textBox2.Text, out age)) { label3.Text = $"Hello {name}, you are {age} years old."; } else { label3.Text = "Please enter a valid age."; } } } }
16 Replies
Gingy
GingyOP2mo ago
every time i try to submit the information put in the response i get is always "Please enter a valid age."
Buddy
Buddy2mo ago
What do you write in textBox2?
Gingy
GingyOP2mo ago
only numbers
Buddy
Buddy2mo ago
any examples?
Gingy
GingyOP2mo ago
25 2
Buddy
Buddy2mo ago
Alright. Make sure there are no invisible characters
Gingy
GingyOP2mo ago
still doesnt work
Pobiega
Pobiega2mo ago
time to learn how to $debug
MODiX
MODiX2mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Buddy
Buddy2mo ago
you can try to use .Text.Trim() My best guess is that there's invisible characters such as CRLF
Gingy
GingyOP2mo ago
in the code or where im inputing values what is CRLF?
Buddy
Buddy2mo ago
textBox2.Text.Trim() Carriage Return Line Feed Basically line break you might also be able to disable accepting return key
Gingy
GingyOP2mo ago
where do i put that line of code
Buddy
Buddy2mo ago
What code?
Gingy
GingyOP2mo ago
actually figured it out i need to work on my design i had my text boxes reversed under the labels
Pobiega
Pobiega2mo ago
you can rename them to give them better names
Want results from more Discord servers?
Add your server