C#
  Home arrow C# arrow Page 11 - Introducing C# and the .NET Framework
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
C#

Introducing C# and the .NET Framework
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 87
    2005-01-31

    Table of Contents:
  • Introducing C# and the .NET Framework
  • The .NET Framework
  • C# Source code
  • The .NET Type Story
  • A World of .NET
  • The Common Language Runtime
  • The Common Type System
  • A World of Interoperability Through the CLS
  • Where Can I Find the .NET SDK?
  • Writing the Hello World Example with the C# Compiler
  • Assemblies
  • Analyzing the Code

  • 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


    Introducing C# and the .NET Framework - Assemblies


    (Page 11 of 12 )

    Every time you compile C# code the file produced (.dll file or .exe file) is called an Assembly. The Assembly is a self-describing component; when you compile the source code files the compiler emits information about the types contained in the application, along with other information that is needed by the runtime (such as what files are needed to run the application). The Assembly is a logical group of one or more files, so you can have one assembly represented as MyAssembly.dll file, and you can have another assembly that consists of more than one file (or module).

    The term "logical group of files" may be confusing for some of you. VS.NET generates a single-file assembly, which means that all the C# source code files will be compiled in one file with an extension .dll or .exe, which is the assembly of the application. The C# Compiler will emit information to tell the assembly that all the program types' definitions are grouped in this file, and that produces a single file assembly.

    If you need to create a multi-file assembly, then you must use the C# Compiler to produce your program as modules and link these modules together using the C# compiler switches. Only one file in the assembly will contain information about the other parts (modules) of the assembly; that's why we call it assembly, because it is a group of one or more files linked together. You may want to produce a multi-file assembly if there are some parts of your program that will be rarely used, so it may be downloaded from the Internet only when needed. You will learn how to produce a multi-file assembly in an upcoming article (".NET Assemblies and Namespaces").

    Namespaces

    Suppose you have a class named Employee that represents an employee in the HR department. In the system there's another Employee class that represents an employee in the IT department. You want to define these classes, so the first thing that come to your mind is, how I can differentiate these separate entities? The answer is "use a namespace."

    A namespace is just a logical organizing of your types to avoid name collision and to effectively organize your application's classes and other types. The .NET Framework uses namespaces to organize its class libraries. For example, the System namespace contains basic data types like Int32 and Int64. It also contains namespaces such as System.IO and System.Text. It's very easy to nest namespaces. Let's see the code for the Employee classes: 

    namespace HR
    {
       class Employee
       {
          // class functionality and code goes here
       }
    }

    namespace IT
    {
       class Employee
       {
          // class functionality and code goes here
       }
    }

    As you can see, the namespace HR contains a class called Employee which we can call using the form namespace.classname, HR.Employee. The IT namespace contains another class called Employee which we can refer to as IT.Employee. The next code can instantiate an object of each class with no problems:

    // creating an instance of the HR.Employee class
    HR.Employee emp = new HR.Employee();
    // creating an instance of the IT.Employee class
    IT.Employee emp2 = new IT.Employee();

    A namespace declaration consists of the keyword namespace followed by an identifier for the namespace. You can nest namespaces as much as you want, but please avoid creating a long hierarchy of namespaces. Microsoft recommends a pattern for using namespaces:

    CompanyName.ApplicationName.ComponentName

    We can represent this pattern in the following namespace declarations:

    namespace Microsoft
    {
       //classes that relate to this namespace goes here
       class BasicFunctionality
       {
       }

       //nested namespaces goes here
       namespace Office
       {
          //classes that relate to this namespace goes here
          class BasicFunctionality
          {
          }

          //nested namespaces goes here
          namespace Word
          {
             //Word classes goes here
          }
       }
    }

    We can create the same structure using a slightly different syntax (which is acceptable if you want to create these nested namespaces across multiple files):

    namespace Microsoft
    {
       //classes that relate to this namespace goes here
       class BasicFunctionality
       {
       }
    }

    namespace Microsoft.Office
    {
       //classes that relate to this namespace goes here
       class BasicFunctionality
       {
       }
    }

    namespace Microsoft.Office.Word
    {
       //classes that relate to this namespace goes here
       class BasicFunctionality
       {
       }
    }

    Now you can create each namespace in one C# source code file and they will be nested.

    More C# Articles
    More By Michael Youssef


     

    C# ARTICLES

    - Coding a CRC-Generating Algorithm in C
    - Cyclic Redundancy Check
    - Handling Methods and Functions
    - Destroying Objects in C#
    - Creating Objects in C-Sharp
    - Classes and Objects
    - Programming Languages: Managed versus Native
    - LINQ-to-MySQL with DbLinq in C#
    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek