.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Assemblies in C#

Posted By:Abhisek Panda       Posted Date: October 30, 2009    Points: 25    Category: C#    URL: http://www.dotnetspark.com  


        When you compile an application, the MSIL code created is stored in an assembly.Assemblies include both executable application files(.exe files)& libraries(.dll extension)for use by other application.

         In addition to containing MSIL,assemblies also include met information(i.e. information about the information contained in assembly,also called as meta-data)and optional resources(sound and picture file, etc).The meta information enables assemblies to be fully self-descriptive.You need no other information to use an assembly,meaning you avoid situations such as failing to odd required data to the system registry and so on,which was often a problem when developing with other platforms.

          This means that deploying applications is often as simple as copying the files into a directory on a remote computer.Because no additional information is required on the target system,you can just run an .exe file from this directory.

         Of course,you would not necessarily want to include everything required to run an application in one place.You might write some code that performs tasks required by multiple applications.In that situation it is often useful to place the reusable code in a place accessible to all applications. In the .NET framework,this is Global Assembly Cache(GAC).Placing code in GAC is simple-you just place the assembly containing this cache.

Creating and using an Assembly/Class Library

To create an assembly or class library in C# select class library project from new project window. Then clock on OK. A new code editor will be opened write the following code in it,

public class Demo
 void show()
  Console.WriteLine("Welcome to Class Library Project");

     Now build the above class library and save it. Now create a new console application. Right click on the project name and click on "add refference". Then browse the class library you now created and add it to your console application.

Then write the following code to use the class library,
using Demo;//Implementing class library in our application
class MyProgram
 static void Main(String args[])
  //creating object of class library class
  Demo d = new Demo();
  //using the show method of the class library

        The output of the above console application will be "Welcome to Class Library Project". Similarly we can use class libraries in different languages of .NET. In VB.NET you have to use "import" instead of "using" to add the class library.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend