C
C#3mo 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
GingyOP3mo ago
every time i try to submit the information put in the response i get is always "Please enter a valid age."
Buddy
Buddy3mo ago
What do you write in textBox2?
Gingy
GingyOP3mo ago
only numbers
Buddy
Buddy3mo ago
any examples?
Gingy
GingyOP3mo ago
25 2
Buddy
Buddy3mo ago
Alright. Make sure there are no invisible characters
Gingy
GingyOP3mo ago
still doesnt work
Pobiega
Pobiega3mo ago
time to learn how to $debug
MODiX
MODiX3mo 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
Buddy3mo ago
you can try to use .Text.Trim() My best guess is that there's invisible characters such as CRLF
Gingy
GingyOP3mo ago
in the code or where im inputing values what is CRLF?
Buddy
Buddy3mo ago
textBox2.Text.Trim() Carriage Return Line Feed Basically line break you might also be able to disable accepting return key
Gingy
GingyOP3mo ago
where do i put that line of code
Buddy
Buddy3mo ago
What code?
Gingy
GingyOP3mo ago
actually figured it out i need to work on my design i had my text boxes reversed under the labels
Pobiega
Pobiega3mo ago
you can rename them to give them better names
Want results from more Discord servers?
Add your server