[Gtk-sharp-list] Gtk.Application.Invoke + anonymous delegates == lots of uints?

Jonathan Pryor jonpryor at vt.edu
Sat Dec 9 15:14:31 EST 2006


On Sat, 2006-12-09 at 11:36 -0200, Rafael Teixeira wrote:
> I checked the code and discovered that Convert.ToString (int) also
> autoboxes the int parameter and calls the ToString override of int32.

You seem to believe that calling .ToString() on a struct requires boxing
the struct.  This is incorrect -- the struct is only boxed if ToString()
isn't overridden, and it *is* overridden on the built-in types.

In other words, this shouldn't cause any boxing:

	uint n = (uint) 42;
	string s = n.ToString ();

It's only the assignment of a value-type to System.Object or an
interface that it must be boxed.  Direct method invocation doesn't
require boxing (unless the method being invoked isn't directly
implemented on the structure, in which case it needs to be boxed in
order to call the base class version -- examples being GetHashCode(),
Equals(), and ToString()).

 - Jon




More information about the Gtk-sharp-list mailing list