The building of dll file in c# is very essay & simple. But it's difficult for beginner.
No doubt that "Every one among pro was a beginner once."
Let i describe the way.
First open a new project as "ClassLibrary" make a class file which will be build as dll file after compiling.
public class BasicCalculation
{
public Int32 add(Int32 a, Int32 b)
{
return (a + b);
}
public Int32 substract(Int32 a, Int32 b)
{
return (a - b);
}
public Int32 multi(Int32 a, Int32 b)
{
return (a * b);
}
public Int32 divid(Int32 a, Int32 b)
{
return (a / b);
}
}
|
Here i make 4 very simple method.
Now we build it as "MyCalculation.dll"
Now we look for the main application.
we must reference our dll file first. The way is Project->Add Reference.
For best way put your dll file in .../bin/debug folder.
then must be use: using MyCalculation;
now for add button the code is following.
using MyCalculation; .....
private void button1_Click(object sender, EventArgs e) { try { Int32 x = Convert.ToInt32(textBox1.Text); Int32 y = Convert.ToInt32(textBox2.Text); // Call dll MyCalculation.BasicCalculation madd = new BasicCalculation();//namespace.class Int32 z = madd.add(x, y);//class.method string ans = Convert.ToString(z); textBox3.Text = ans; } catch { textBox3.Text = "Wrong Input!"; } }
|
Now run the program. And you get your recommended out put with the help of dll.
i upload the sample example. Hope you will now make dll file, and say wow it's very essay as it is. :-)
Thank you!
rishi royPosted Jul 26, 2010, 12:04 AM
Thanks for your simple code, it help me to understand the concept of dll as i am a beginner...