10May/100
Explain constructor and destructor with an example using C#.NET.
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
}
}
21Dec/090
Basic interview questions for C# Component Developers
- Explain the differences between public, protected, private and internal.
- What benefit do you get from using a Primary Interop Assembly (PIA)?
- By what mechanism does NUnit know what methods to test?
- What is the difference between typeof(foo) and myFoo.GetType()?
- Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
- What is this? Can this be used within a static method?
- Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
- What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
- Juxtapose the use of override with new. What is shadowing?
- Explain the use of virtual, sealed, override, and abstract.