.NET constructors and destructors - October 30, 2008 at 18:10 pm
by Amit Satpute
Explain constructor and destructor with an example using C#.NET.
A constructor is a member function that performs the task of initializing the
objects with the default values to be assigned after creation.
A destructor is a function that is run to release the resources held by an
object when it is no longer needed by the application.
In C#.NET we can create constructor and destructor in the following manner:
-----------------CONSTRUCTOR---------
class C
{
private int
x;
private int y;
public C (int i, int j)
{
x = i;
y = j;
}
public void display
()
{
Console.WriteLine(x + "i+" + y);
}
}
-----------------DESTRUCTOR---------
class D
{
public D()
{
//
constructor
}
~D()
{
// Destructor
}
}
<<Previous
Next>>
Also read
Object Serialization in .NET
Explain about Serialization in .NET. Explain binary serialization and XML
serialization.
What is Formatters? Explain the binary formatter and the SOAP formatter.
Explain why Serialization.
Explain the components that comprise the binary serialization
architecture......
Common Language Runtime is a run time environment for .NET..........
CTS define how these different variables are declared and used in run
time...........
Boxing permits any value type to be implicitly converted to type object or to
any interface type Implemented by value type.............
Operator overloading is the most evident example of Polymorphism. In operator
overloading, an operator is ‘overloaded’.............
Object.Finalize method in .NET is typically used to clean and release unmanaged
resources like OS files, window etc..............
|