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


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using class libraries in C#

Posted By:Abhisek Panda       Posted Date: October 30, 2009    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  
 

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

d.show();

}

}


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.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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