AIM : Design an application that uses the user defined Dynamic Link Library in Window Application.
Source Code :
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;
using ClassLibrary1;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int a, b, c;
Class1 o = new Class1();
public Form1()
{
InitializeComponent();
}
// Addition
private void button1_Click(object sender, EventArgs e)
{
a = Int32.Parse(textBox1.Text);
b = Int32.Parse(textBox2.Text);
c = o.add(a,b);
MessageBox.Show("Addition is "+c.ToString());
}
// Subtraction
private void button2_Click(object sender, EventArgs e)
{
a = Int32.Parse(textBox3.Text);
b = Int32.Parse(textBox4.Text);
c = o.sub(a,b);
MessageBox.Show("Subtraction is " + c.ToString());
}
// Swaping
private void button3_Click(object sender, EventArgs e)
{
a = Int32.Parse(textBox5.Text);
b = Int32.Parse(textBox6.Text);
o.swap(ref a,ref b);
textBox5.Text = a.ToString();
textBox6.Text = b.ToString();
}
// Factorial
private void button4_Click(object sender, EventArgs e)
{
b = Int32.Parse(textBox7.Text);
c=o.fact(b);
MessageBox.Show("Factorial is " + c.ToString());
}
}
}
// Class Liberary
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public int add(int a, int b)
{
return (a + b);
}
public int sub(int a, int b)
{
return (a - b);
}
public void swap(ref int a, ref int b)
{
int c;
c = a;
a = b;
b = c;
}
public int fact(int b)
{
int a = 1;
for (int i = b; i > 0; i--)
{
a = a * i;
}
return a;
}
}
}
Output