.NET
  Home arrow .NET arrow Page 2 - .NET Type System, Part I
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

.NET Type System, Part I
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 44
    2005-03-08

    Table of Contents:
  • .NET Type System, Part I
  • The ILDASM.EXE Tool
  • System.Object Class
  • The Stack and the Heap
  • Structures: complex Value-Types
  • Enumerations

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    .NET Type System, Part I - The ILDASM.EXE Tool


    (Page 2 of 6 )

    The .NET SDK includes a tool called ILDASM.EXE (Intermediate Language Disassembler) that you can use to inspect the generated .NET Assemblies and see the byte code instructions. For this section copy the following code, paste it into notepad, and save it as HelloILDASM.cs.

    using System;

    namespace HelloILDASM
    {
      public class Class1
        {
          static void Main()
          {
            Console.WriteLine("Hello ILDASM from C#");
          }
        }
    }

    Compile the application using the following command (note that I saved the file on drive C on my machine).

    C:\csc HelloILDASM.cs

    Use the following command to load the application with the ILDASM tool

    C:\ildasm HelloILDASM.EXE

    And this is exactly what you will get:

    First of all, let's learn more about these icons. Examine the table below.

    IconDescription

    This is a namespace in the loaded assembly; here we have the HelloILDASM namespace.

    This is a Reference Type symbol. We use this icon for Class1 (which is of course a Reference Type).

    This is a structure Type symbol; it's the same shape as the Reference Type, but a different color.

    This is an Interface symbol. In .NET there are some naming conventions, such as preceding the interface name with the I letter, as in IDisposable interface.

    This is an Enumeration type icon.

    This red arrow means more information can be obtained.

    This symbol represents an instance method.

    The S letter on the method symbol means that it's a static method.

    This symbol represents a field.

    This is a Property symbol.

    This is an Event symbol.

    This is the symbol for a static field or a constant.

    Understanding MSIL is beyond the scope of this article, but we will take a quick look at the MSIL Instructions. It's good for you to understand  the MSIL code that the C# compiler generates from your source code, and in fact it will help you understand many concepts and give you the ability to develop better applications.

    All the classes in the .NET Framework derive from a common base class which is called Object and lives in the System namespace. To illustrate this, double click on the More Information Icon of the Class1 class and the following class declaration window will be shown:

    Actually this is no more than declaring a class (Class1) which is public and extending the class System.Object which lives in the assembly mscorlib. We didn't define that our Class1 would extend and inherit from System.Object; it's implicitly done for us by the C# Compiler. We will talk about this class soon. Close this window and double click on the .ctor(): void method and the next window will be shown:

    This method declaration is the default constructor for our class Class1, and it does nothing more than call the System.Object constructor using the MSIL Instruction call. The method is marked as Managed Code using the cil managed keyword. Close this window and double click on the Main: void(). The next window will be shown:

    As you know, every C# application has an entry point, and it's always the Main method. Here the .entrypoint defines the Main method as the application's entry point. Our C# source code was very simple; we just made a call to Console.WriteLine() method and passed the string "Hello ILDASM from C#". Let's see what the C# compiler has generated in the compiled assembly file.

    IL_0000: ldstr   "Hello ILDASM from C#"
    IL_0005: call     void [mscorlib]System.Console::WriteLine(string)
    IL_000a: ret

    The MSIL code is a series of instructions that the CLR executes. The first instruction is ldstr, which loads the specified string constant onto the stack. The next instruction, call, calls the method System.Console.WriteLine(string). The method argument is taken from the stack and nothing is put back -- because the method returns void, which means that the method doesn't return a value.

    I don't want to delve into a lot of details about the MSIL Instructions because it would fill a book. But I will show you the MSIL code in a lot of articles until you get used to it. It will help you understand the code that gets generated under the hood. It's not that difficult and you will not need to write .NET Applications using IL Assembler; in most cases you will be using C#.

    More .NET Articles
    More By Michael Youssef


     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT