Once a 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 it can be reused from any other programming languages of .Net; i.e., .Net components or assemblies will provide language interoperability.
To create components in .Net, we use class library templates.
End user will never interact with some applications; but will interact with components 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;
- }
- }
- }
Building 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.