A noobs question :)

+1 Kerem Etes · January 5, 2015
Hi , just wanted to ask a real quick question about C#

I'm using Microsoft Visual C# 2010 Express and on a form I have a textbox and a button. I just simply want to assign a variable to the text box's user input so that the variable will change depending on what I type in the text box. I couldn't figure out what the correct syntax is. Hope you can help 

I basically want to type a name in the text box then press the button and depending on what the text box input is the message will print out a message but as a variable.

Just declaring a variable then trying to assign it to the text box didn't work.


Post a Reply


Oldest  Newest  Rating
-1 Daniel Nachum · January 15, 2015
you could also do this:

Output(""+intFromString *2);
0 Kerem Etes · January 11, 2015
Thanks Eugene. 

Sometimes I go blind to see the simplest things :) . You're right I should have added .ToString().
0 Eugene Botma · January 11, 2015
Here it would be very beneficial to read the error message. It should say something like " 'projectname.output(string)' has some invalid arguments", then below that: "Argument 1: cannot convert from int to string".

This means that the Output method requires a string as an argument, but you're giving it an int. Simply convert or parse the int to a string.

Output((intFromString * 2).ToString());

In visual studio, if you type the name of the method and then enter the opening bracket, a popup shows that should explain what the method does (if available) and what the arguments should be. It's always a good idea to look at the information when using a method.
0 Kerem Etes · January 10, 2015
Ok here is my second noob's question :). I have two instances of a code and I know for a fact the second code method is applied wrong (by me ). I want to know the reason why I cant  double the intFromString by 2 in the second screenshot I added. Is it because my intFromString's value is actually referred and not changed  ? Hope someone can enlighten me :) 

Thanks .



0 Kerem Etes · January 6, 2015
Thanks a lot, Yes it helped :) I was going crazy for such a simple thing :).
0 Gabriel Felipe · January 6, 2015
Just double-click the button and type: 

            string msg;
            msg = textBox1.Text;

and if you want to use this variable outside of the button, just declare it directly in the main class as public  like that: 

public partial class Form1 : Form
        public string msg;

Hope i helped ;D
  • 1



C# is an object-oriented language designed for improving the development of web applications.