Using Class Libraries in C#

Posted by Abhisek under C# category on | Views : 4829
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 reference". 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.

Comments or Responses

Login to post response