There are 2 compiled versions of the code that is produced the C# compiler:
- First, it is compiled into Common Intermediary Language (CIL). You can look at this by using the
ildasm
command in a Visual Studio Command Prompt or by using a (better) tool like Redgate's .NET Reflector
- It is then compiled from CIL to native machine code (by the Just In Time Compiler) and run. You can view this code by going
Debug > Windows > Disassembly
in Visual Studio.
But you are interested in the memory representation of the native types. This may be difficult and hard to grasp, but if you feel like you're up to it you can use WinDbg
and SOS.dll
to debug Managed Code in a native way. I would look at this list of links to get you started. Just google "SOS.dll" for more information.
I don't think you will be able to (easily) do this programatically at all from the CLR. Maybe (big maybe) if you used NGEN to compile your assemblies ahead-of-time then use some sneaky C or C++ you might be able to do this, but it would be extremely hard (this is out of my knowledge zone, someone who works on the JIT team might be able to help you)