Coffeehouse Post

Single Post Permalink

View Thread: .NET Assembly for beginners?
  • User profile image

    1.  Check out .NET Reflector.  It should be able to show you some C# code for a given assembly regardless of whether it was originally compiled with ilasm or any other compiler.  Here's a link:

    2.  The Visual Studio debugger doesn't support "disassembling" to IL.  Not sure about other tools out there. 

    3.  Console.WriteLine has several overloads including one that takes an Int32.  In the C++ code snippet you provided, you're explicitly boxing the value before passing it to Console.WriteLine.  If you don't do that, it should probably just work without boxing.  The C# compiler will automatically box the int if it needs to.  In the case of Console.WriteLine, it doesn't need to.  If you use something that just takes an object, such as ArrayList, then you'll see that C# will box it for you.

    4.  The VB and C# compilers don't always emit exactly the same IL.  But it'll probably be pretty similar for the most part.  I think the simple answer to your question is yes, it's one IL for everything.  There are features supported by the CLR that are not supported by all .NET languages.  But in general, interop between languages is great.

    5.  Someone who can read IL will be able to better understand what the code they wrote in a higher-level language (C#, VB, etc.).  We, on the compiler team, read IL very often.  It's one of the first steps we take when trying to figure out if a bug is in the compiler or the JITter or elsewhere.  That said, I'm not sure it's a huge advantage to know IL fluently in general.  It'll sure help, but I don't know of many people that find themselves writing code in IL very often. 

    Hope that helps,