tags:

views:

172

answers:

5

I need to show an integer value in a TextBox in my C# windows forms application (GUI). I have an int32 value available. I could not find a container like a TextBox that takes int values. The TextBox only accepts Strings. How do I type cast? Any help is much appreciated.

Thanks, Viren

+1  A: 
int i = 10;
TextBox1.Text = i.ToString();
David Stratton
+1  A: 

TextBox.Text = MyInteger.ToString();

Mark Redman
+1  A: 

You can use the ToString() method to convert the integer to a string.

int x = 10;

Console.WriteLine(x.ToString())

Crappy Coding Guy
+1  A: 

Everything in .net can be transformed to a string in one way or another by using the "ToString()" method.

int x = 5;
string y = x.ToString();
womp
Leads to many a classname too eh, Womp ;)
Daniel Elliott
It sure does :)
womp
+1  A: 

You can do this in many ways:

        int i = 123893232;
        Console.WriteLine(i.ToString());//123893232
        Console.WriteLine(Convert.ToString(i));//123893232
        Console.WriteLine(String.Format("{0:C}", i));//123 893 232,00 zł(Polish)
        Console.WriteLine(String.Format("{0:D}", i));//123893232
        Console.WriteLine(String.Format("{0:E}", i));//1,238932E+008
        Console.WriteLine(String.Format("{0:F}", i));//123893232,00
        Console.WriteLine(String.Format("{0:G}", i));//123893232
        Console.WriteLine(String.Format("{0:N}", i));//123 893 232,00
        Console.WriteLine(String.Format("{0:P}", i));//12 389 323 200,00
        Console.WriteLine(String.Format("{0:X}", i));//76275F0
mykhaylo