[IronPython] C#, Types and IronPython

Michael Foord fuzzyman at voidspace.org.uk
Sun Mar 11 16:08:21 CET 2007


Nicholas Riley wrote:
> On Sun, Mar 11, 2007 at 02:27:11PM +0000, Michael Foord wrote:
>   
>> What object does 'typeof(int)' (in C# *not* IronPython) return. I guess 
>> it is not System.Int32 !
>>     
>
> Indeed it is; I'm not sure why you're confused about this when a
> one-line C# program will give you the answer :-)  typeof(int) is
> converted by the C# compiler into the following IL:
>
> ldtoken    [mscorlib]System.Int32
> call       class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
>
> which makes it pretty clear that System.Int32 is specified at compile
> time.
>
>   
>> Is there a common base class for the C# number types ?
>>     
>
> No; however there are several common interfaces these types implement,
> such as IConvertible.
>
>   
Ok - cool. That's very helpful. I'm still not really used to the idea of 
decompiling assemblies to get this sort of information.

Several of the MSDN examples use 'typeof(int)', why not just specify 
'Int32' ? I guess it makes the code less platform dependent ?? Oh well.

Thanks

Michael




More information about the Ironpython-users mailing list