So first from file menu select the project option, then
select the class library,named it as you wish after cliking ok by default a classlibrary1 has created and inside that a class1 also created.
Inside this class1 you should placed your methods which you wish to use in other project files. After creating the class you should build it.To build it you must save the file first then from build menu select
build> build classlibrary1.
After a successful build,you close this file, and open a new project where you wish to use this dll. From the project menu select add reference,the add reference window will shown , then choose the browse button and browse the dll file where you store it for example->
projects->classlibrary1->bin->debug
or bin->release
and locate the dll file. Now you able to use it in your project.You must call the namespace, to use the methods inside the dll.( using namespace_name;)
Here we use the createdll the dll file
Expand|Select|Wrap|Line Numbers
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using createdll;
- namespace WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- long a, b;
- a = long.Parse(textBox1.Text);
- b = long.Parse(textBox2.Text);
- textBox3.Text = math.add(a, b).ToString();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClassLibrary1
- {
- public class Class1
- {
- public static long add(long a, long b)
- {
- return (a + b);
- }
- }
- }
Note: After successful build of this class will create a dll file( here ut ClassLibrary1.dll