Assigning Values

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Hi All,

I am trying to assign an int value to a textbox. Of course C# doesn't
like this so is common to use Convert.toInt32 textboxs with numbers then use
Convert.toString assign the values back into the Textboxs? Like the
following:

tbEstLMPOnPeak.Text = Convert.ToString(Convert.ToInt32(tbTotNetOnPeak) -
1224);



Thanks,

JJ
 
yes thats correct but you are doing the same thing that I did but in long
form.

I guess I am use to vb where it didn't matter what you put into a textbox
the conversion was autonatically done for you behind the scenes.

Why not c#, I guess is my question?

Thanks,

JJ
 
JJ said:
yes thats correct but you are doing the same thing that I did but in long
form.

I guess I am use to vb where it didn't matter what you put into a textbox
the conversion was autonatically done for you behind the scenes.

Why not c#, I guess is my question?

Because C# is strongly typed - and a good job too, IMO.
 
Yes, but if you have a lot of integer text boxes I would consider deriving
your own class from TextBox with an int property (Value, for example) that
you can get/set the int value. Then just do the conversion inside that class
rather than everywhere in the client.

Or search for someone else's existing integer text box class, e.g.
http://dotnet247.com/247reference/msgs/10/52054.aspx
 
Back
Top