user defined class libraries or Dlls

Ersudeep13
Posted by Ersudeep13 under .NET Framework category on | Points: 40 | Views : 1257
Component--> A component is reusable piece of code and is in the form of DLL.

Once component is designed it can be reused from any kind of application like in console application or windows application or web application or device application etc.

Once a component is designed in any programming language of .net that can be reused from any other programming languages of .Net i.e. .Net components are or assemblies will provide language interoperability.
To create component in .Net, we use class libraries templates.
End user will never interact with some application will interact with component or DLL.

program for creating a Component / Assembly

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

namespace CLibMaths
{
public class Arithmatic
{
public int Num1, Num2, Result;
public int PNum1
{

set { Num1 = value; }
get { return Num1; }
}
public int PNum2
{
set { Num2 = value; }
}
public int PResult
{
get { return Result; }
}
public int Add()
{
Result = Num1 + Num2;
return Result;
}
public void Subtract()
{
Result = Num1 - Num2;
}
public void Multiply()
{
Result = Num1 * Num2;
}
public void Divide()
{
Result = Num1 / Num2;
}
}
}

ADD a new class with name ClsMathNumbers
Change the accessibility of the class to public and write following code

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

namespace CLibMaths
{
public class ClsMathNumbers
{
public int Square(int x)
{
return x * x;
}
public int Cube(int x)
{
return x * Square(x);
}
public int Factorial(int x)
{
int R = 1;
for (int i = 1; i <= x; i++)
{
R = R * i;
}
return R;
}
}
}

Build the solution will create a DLL. this dll is known as .net component
to see the DLL go to the \bin\Debug folder of the application , you find the CLibMaths.dll

Comments or Responses

Login to post response