-
December 4th, 2008, 11:25 PM
#1
Display a variable
Can someone help me?
I have a variable
int ten = 10;
and i want to display it ive tried things like
textbox1.text = ten;
textbox1.text = (ten);
and many other things but they didnt work :-(
-
December 5th, 2008, 01:21 AM
#2
Re: Display a variable
Code:
textbox1.Text = ten.ToString();
The Text property of a TextBox is of type string, but you are trying to assign an int to it. The "ToString()" method of an object returns a string representation, so you can assign that to the Text property. It would probably be a good idea for you to go through some beginner C# tutorials to get the basic syntax and programming concepts down.
Last edited by BigEd781; December 5th, 2008 at 01:23 AM.
-
December 5th, 2008, 02:10 AM
#3
-
December 9th, 2008, 01:19 AM
#4
Re: Display a variable
Gunnar,
Also look at the String.Format(...) method, as I suspect sometimes you will want to display many variables at once:
Code:
textbox1.Text = String.Format("{0}", ten);
// output "10"
textbox1.Text = String.Format("The number is {0}", ten);
// output "The number is 10"
textbox1.Text = String.Format("My IQ is {0} and this is the end of the paragraph{1}{1}", ten * 15, Environment.NewLine);
// output "My IQ is 150 and this is the end of the paragraph" followed by 2 new lines.
hope that helps. (I took care not to use 10 in the last statement
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|