C
C#2y ago
! dubby

❔ ✅ C# .NET issue, pretty simple problem but im new lol

hi, i want my program to say the persons username after, but im not sure what the code needs to look like for it
21 Replies
! dubby
! dubbyOP2y ago
! dubby
! dubbyOP2y ago
this is my current code
friedice
friedice2y ago
$paste
MODiX
MODiX2y ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
friedice
friedice2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
! dubby
! dubbyOP2y ago
BlazeBin - yicspfvqjubq
A tool for sharing your source code with the world!
friedice
friedice2y ago
you can do string interpolation
var string = $"{Username.text} is my username";
var string = $"{Username.text} is my username";
! dubby
! dubbyOP2y ago
what would the whole code need to look like?
friedice
friedice2y ago
private void guna2Button2_Click(object sender, EventArgs e)
{
try
{
KeyAuthApp.register(Username.Text, Password.Text, License.Text);
if (KeyAuthApp.response.success)
{
Username.Text = null;
Password.Text = null;

MessageBox.Show("Successfully Registered! + (Username.Text)", "KeyAuth", MessageBoxButtons.OK, MessageBoxIcon.Information);

MainForm lol = new MainForm();
lol.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid License - Contact Support", "KeyAuth - Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void guna2Button2_Click(object sender, EventArgs e)
{
try
{
KeyAuthApp.register(Username.Text, Password.Text, License.Text);
if (KeyAuthApp.response.success)
{
Username.Text = null;
Password.Text = null;

MessageBox.Show("Successfully Registered! + (Username.Text)", "KeyAuth", MessageBoxButtons.OK, MessageBoxIcon.Information);

MainForm lol = new MainForm();
lol.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid License - Contact Support", "KeyAuth - Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
this is your method right. What are username and password in this context Username and Password
! dubby
! dubbyOP2y ago
im using keyauth so it depends what the person registers with
! dubby
! dubbyOP2y ago
friedice
friedice2y ago
it looks funky but webforms arent my expertise so ill overlook it Hmm if you put an an object inside " " it becomes a string unless you do string interpolation
var User = new User() {Name = "Bob");
Console.WriteLine("Hi I'm User.Name"); // prints out Hi I'm User.Name
Console.WriteLine($"Hi I'm {User.Name}"); // prints out Hi I'm Bob
var User = new User() {Name = "Bob");
Console.WriteLine("Hi I'm User.Name"); // prints out Hi I'm User.Name
Console.WriteLine($"Hi I'm {User.Name}"); // prints out Hi I'm Bob
! dubby
! dubbyOP2y ago
i think i got it working my friend helped me with a different method but now i have this issue
! dubby
! dubbyOP2y ago
the username and password get deleted when i press register
friedice
friedice2y ago
what's this for anyways
! dubby
! dubbyOP2y ago
im messing around with GUIs to learn more about them, since i havent been coding for long its not really for anything, just to enhance my learning
SeanJ
SeanJ2y ago
MessageBox.Show("Successfully Registered! + (Username.Text)", "KeyAuth", MessageBoxButtons.OK, MessageBoxIcon.Information); The errors I see here is string interpolation as IceGPT said. Just so you fully understand. To use string interpolation you need to do this:
var myString = $"{var.property}";
var myString = $"{var.property}";
We include a $ sign before the string and encapsulate your variables in {} rather than round brackets not this:
var myString = $"(var.property)";
var myString = $"(var.property)";
! dubby
! dubbyOP2y ago
!close
Accord
Accord2y ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server