How to write a method in a class and build as .dll

 Posted by Poster on 6/16/2009 | Category: C# Interview questions | Views: 3588

To generate a .dll you can following below steps

1. Right click your solution and select New Project.
2. Select Visual C# as Project type and Class Library as Templates (give proper name and location path) and click OK.
3. Write some code in the class like below, you can add as many class you want.
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ClassLibrary1
public class Class1
public string GetMyName(string myName)
return myName;

4. Right click the Class Library project and select build.
5. Your .dll should be ready in the bin folder of the project location (either in the debug or release folder) depends on which mode your project is.
6. To refer this .dll, you can right click your project and select Add References.
7. Select browse tab from the dialogue box and choose the .dll you have just generated.
8. Now to use the method of the class library in any code behind page or another class library, you can use the namespace you had used in the class library (in above case ClassLibrary1) like "using ClassLibrary1;"
9. Instantiate the class and use its method like below
Class1 c = new Class();

string myName = c.GetMyName("Poster");

Thanks :)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Vuyiswamb on: 6/17/2009
That is Good
Posted by: Mcadeepuraj on: 8/12/2011 | Points: 10

Login to post response