By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

TextBox.text = int (does boxing happen here)

P: n/a
This might sound like a stupid question, but anywas

when you assign an int to a textbox via the textbox.text propperty I
assume boxing happens. If this assigment happend too often rapidly on a
GUI wont it be a performance step back? Is there a more efficient way
of assigning other value types to a textbox?

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Boxing does not occur, but you must convert the int to a string. Here
is some code that assigns an int to a textbox.text property:

int theInteger = 25;
textBox1.Text = Convert.ToString(theInteger);

And here is the IL generated: There is no boxing involved.

// Code Size: 21 byte(s)
.maxstack 2
.locals init (
int32 num1)
L_0000: ldc.i4.s 25
L_0002: stloc.0
L_0003: ldarg.0
L_0004: ldfld [System.Windows.Forms]System.Windows.Forms.TextBox
TestCs.Form1::textBox1
L_0009: ldloc.0
L_000a: call string [mscorlib]System.Convert::ToString(int32)
L_000f: callvirt instance void
[System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
L_0014: ret

Nov 17 '05 #2

P: n/a
TextBox.Text is a string, not an object. Strings don't box.

If you want to attach something besides a string to a TextBox, you can
always use the Tag property.

Pete
"Tariq" <ta*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
This might sound like a stupid question, but anywas

when you assign an int to a textbox via the textbox.text propperty I
assume boxing happens. If this assigment happend too often rapidly on a
GUI wont it be a performance step back? Is there a more efficient way
of assigning other value types to a textbox?

Nov 17 '05 #3

P: n/a
Pete Davis wrote:
TextBox.Text is a string, not an object. Strings don't box.


Strings *are* objects (so they don't need to box).

Hans Kesting
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.