C# .NET - CREATE Class Library in windows application in C# visual studio 2010

Asked By Warjie Malibago
13-Jun-11 11:11 PM
hi,how can i create a class library in my windows form in C#? thanks a lot
  Mihir Soni replied to Warjie Malibago
13-Jun-11 11:18 PM
Hello,

To create class library in windows application follow the steps.

  1. Create New Project
  2. Select Class Library Project
  3. Write your all the functions required by you
  4. Build that project
  5. Go to your BIN directory you will be able to see DLL file with the same name of your project.
  6. Now to use this DLL in your windows application
  7. Right Click on solution explorer
  8. Click on Add reference
  9. Locate the DLL which we have build in step 4,5
  10. And now just import that in your CODE file you will be able to access all the functions
Hope this helps you

Let me know if you need more information regarding this.

Thank you.
  Riley K replied to Warjie Malibago
13-Jun-11 11:28 PM
Create a new project and select Class Library,

Write all your code methods, and remember the namespace, you have to reference using this namespace.

Now build the solution, after the build is succeded you can see the DLL in your Project Bin folder,

In any of other of your project to use this DLL right click on solution explorer, select add reference and from browse select your DLL.

use the namespace of the class library, that's it.
  Vickey F replied to Warjie Malibago
13-Jun-11 11:33 PM

You can create a class library of your code, save it as a DLL and then reuse your C# code in other projects. The process is quite straightforward.

Start a new project. From the New Project dialogue box, select Class Library instead of Windows Application.

After that follow the steps in which are given in these links-

http://www.homeandlearn.co.uk/csharp/csharp_s16p1.html
http://www.dotnetheaven.com/Uploadfile/mahesh/pr1202172006014101AM/pr12.aspx

Here you will get pictorial representation.

Hope this will help you.

  Warjie Malibago replied to Mihir Soni
13-Jun-11 11:34 PM
thank you but how can i call that class library i made in my windows form? what's the code for that?
  Warjie Malibago replied to Riley K
13-Jun-11 11:35 PM
thank you but how can i call that class library i made in my windows form? what's the code for that?
  Warjie Malibago replied to Riley K
13-Jun-11 11:41 PM
this is my code in calling it in my button click:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace ClassLibrary1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

int fNum = Convert.ToInt32(textBox1.Text);

int sNum = Convert.ToInt32(textBox2.Text);

int ret = ClassLibrary1.Class1.Add(fNum, sNum);

}

}

}



but when i debug it,an error appears saying:

A project with an Output Tye of Class Library cannot be started.

it said that I should add an executable project to my solution,,but i don't know how to do that
  Warjie Malibago replied to Riley K
13-Jun-11 11:41 PM
this is my code in calling it in my button click:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace ClassLibrary1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

int fNum = Convert.ToInt32(textBox1.Text);

int sNum = Convert.ToInt32(textBox2.Text);

int ret = ClassLibrary1.Class1.Add(fNum, sNum);

}

}

}



but when i debug it,an error appears saying:

A project with an Output Tye of Class Library cannot be started.

it said that I should add an executable project to my solution,,but i don't know how to do that
  Riley K replied to Warjie Malibago
13-Jun-11 11:46 PM

1- From the project menu, select "Add Reference"
you will be prompted with the add reference dialog
2- Click on the browse button to locate your Class library (usually, a DLL file)


once you have done that, you should see a reference to your class library in Solution Explorer window.

once you  are done with this you can refer witht the namespace name, by Using namespace stmnt.

now you can access all the classes and methods from that DLL

Thanks
  Warjie Malibago replied to Riley K
13-Jun-11 11:53 PM
is is

using namespace ClassLibrary1;

that's the name of my namespace. where should i put it? Should i put it inside the Class or inside the Form's Code? thanks
  Riley K replied to Warjie Malibago
14-Jun-11 04:00 AM
using System.Xml;
using System.Xml.Serialization;
using ClassLibrary1;
namespace console1
{
    class Program
    {
      static void Main()
      {
        // here you can access classes, methods etc of class library
     }
    }

}

like the above code you have to refer to the class library 
Create New Account
help
C#.Foundation Hi . . How can I Take Instance of This Code ? class system { class Array { internal vois show() { console.write("U divit") } } } can I take instance ? ; I think you can. Following scenario works:- public class MYSystem { public class MyArray { internal void show() { MessageBox .Show( "U divit" ); } } } private void Form1_Load( object sender EventArgs e) { MYSystem . MyArray objMyArray = new MYSystem . MyArray (); objMyArray.show(); } Any concerns? The "Array" class in your example would be visible to all other class within the assembly that it resides in. The assembly. The "Show" internal method would behave
visitors count somebody send me the code for visitors count? For that you have to use Application varaible - use this code in global.asax file Private Sub Application_Start ( ByVal sender As Object , ByVal e As EventArgs ) ' Code that runs on application startup Application( "OnlineUsers" ) = 0 End Sub Private Sub Session_Start( ByVal sender As Object , ByVal e As EventArgs) ' Code that runs when a new session is started Application . Lock () Application ( "OnlineUsers" ) = CInt ( Application ( "OnlineUsers 1 Application . UnLock () End Sub Private Sub Session_End ( ByVal sender As Object , ByVal e As EventArgs ) ' Code that runs when a session ends. ' Note : The Session_End event is raised only when the
partial class in .net hi all, what is partial class in .net? how to create a partial class in asp.net? if possible please give me some example so that i can make it use full . . . . . thanks hi, hi, Definition : Partial types are allow to define a single class in multiple files (more than one file), when compilation time theses classes are combined to form a single class. The partial modifier is not available on delegate or enumeration declarations. In old days when we write a big class it gets difficult to read the code of whole class. C# solves this problem through partial classes. With the help of partil calsses we can
Binding the gridview label with class property I have two classes one class called version and it is called another class called version1. i have one to many realtionship between version and version1. below is my class code public class Version { private List<Version1> _Version; public List<Version1> Version { get { return _Version; } set { _Version = value public void AddVersion(Version1 version) { version1.Add(version); } } My Version1 class looks like below public class Version1 { private String _action; public String Action { get { return _action; } set { _action = value; } } } In my
abstract class and interface What is abstract class and interface ? What is diffrence between them ? And in what instance we use abstract class and interaface . Please give some live exmple Hi, The most real time example of abstract class and interface is bulding a house , you create a class say House and then another say Shop both extend Building but you decide to make Building as an abstact class as when you create an object of the building class you don't know which kin of object it will be; will it be house or shop so the program fails and you say ah it is good that this class is made an abstract as we shouldn't create an object of this class. Interface