Sponsored Ad

Thursday, October 22, 2009

C# Component

Component is a class with the cleanup and containment. A component can be placed in a container, and has the ability to query and get services from its container. Containment is logical and not have to be visual. These components can be deployed in mid-level container as business components. Example of database components deployed in the middle level.

Let's see how to create a simple component in C # and how to use a client program. For an example I am taking part in arithmetic, which makes the addition. This component has two properties and a method. Properties to take input for the addition and (...) method is the addition sum.
Let's create a component called csAddComp1 and the package of this component in a DLL (Dynamic Linked Library). And we will use this library in a client program to access the components.

To create properties in C# they have get & set accessors. The get accessor is used for getting (reading) & set accessor for setting (writing) the property.

Example:

using System;
namespace CompCS
{
public class csAddComp1
{
private int i=0,j=0;
public int varI
{
get { return i; } //this is property get for varI
set { i=value; } //this is property set for varI
}
public int varJ
{
get { return j; } // this is property get for varJ
set { j=value; } // this is property set for varJ
}
public int Sum()
{
return i+j; //this returns the sum of two variables
}
} //end of class
} //end of namespace

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers