Interview Tips Interview Tips, Interview Questions and Answers

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

    1. Explain the differences between public, protected, private and internal.
    2. What benefit do you get from using a Primary Interop Assembly (PIA)?
    3. By what mechanism does NUnit know what methods to test?
    4. What is the difference between typeof(foo) and myFoo.GetType()?
    5. Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
    6. What is this? Can this be used within a static method?
    7. Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
    8. What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
    9. Juxtapose the use of override with new. What is shadowing?
    10. Explain the use of virtual, sealed, override, and abstract.