c# - Why calling some functions of the Object class, on a primitive type instance, need boxing? -


I've found that if I run the following lines of code.

  int i = 7; I.GetHashCode (); // where getHashCode () is the // function received from the system. Object  

No sparring has been done, but if I i Call GetType () (Function derived from the System.Object from the other GetHashCode () , , a boxing to Calling GetType () will not be possible, why it is not possible without boxing it is possible to call GetHashCode () , while without boxing, on the initial type of example The key here is to GetType () call

The key here is that < Code> GetType () is not virtual and overrides Since a stat is effectively sealed , the structure can not be overridden at any more , hence runtime and compiler structure methods Which is overridden as a static call.

If you type a straight (rare) you should all methods like ToString ( ) , equal) , GetHashCode () for this reason if you do not do this box Should Ona. However, GetType () can not be override, thus boxing is required.

This is actually Nullable & lt; T & gt leads to some weird edge cases faucet for a blank Nullable & lt; T & gt; Since Box and Boxing, therefore:

  int i = obj GetHashCode (); // OK type T = obj.GetType (); // bounce  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -