Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Why To Use "using" Statement In C#?

Answer»

The using BLOCK is used to OBTAIN a RESOURCE and USE it and then automatically dispose off when the execution of block completed.

The using block is used to obtain a resource and use it and then automatically dispose off when the execution of block completed.

2.

What Is The Difference Between “dispose” And “finalize” Variables In C#?

Answer»

Dispose() Method

  • Dispose method will be used to free unmanaged RESOURCES like files, database connection etc.
  • To clear unmanaged resources we NEED to write code manually to raise dispose() method.
  • This Dispose() method BELONGS to IDisposable interface.
  • If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.

 Finalize() Method

  • Finalize method also free unmanaged resources like database connections, files etc.
  • It is automatically raised by garbage COLLECTION mechanism whenever the object goes out of scope.
  • This method belongs to object class.
  • We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process done.

Dispose() Method

 Finalize() Method

3.

Difference Between Const, Readonly And Static Readonly In C# ?

Answer»
  • Constant variables are declared and initialized at compile time. The value can't be changed after words.
  • READONLY variables will be initialized only from the non-static CONSTRUCTOR of the same CLASS.
  • Static Readonly variables will be initialized only from the static constructor of the same class.

4.

What's The Difference Between The 'ref' And 'out' Keywords?

Answer»

An ARGUMENT passed as "REF" must be initialized before passing to the METHOD whereas "out" parameter needs not to be initialized before passing to a method, and it will be initialized inside the method.

An argument passed as "ref" must be initialized before passing to the method whereas "out" parameter needs not to be initialized before passing to a method, and it will be initialized inside the method.

5.

Is It Possible For A Class To Inherit The Constructor Of Its Base Class?

Answer»

No. A CLASS cannot INHERIT the CONSTRUCTOR of its BASE class.

No. A class cannot inherit the constructor of its base class.

6.

Can 'this' Be Used Within A Static Method?

Answer»

No.

No.

7.

What Is 'this' Pointer?

Answer»

'this' POINTER REFERS to the CURRENT OBJECT of a CLASS.

'this' pointer refers to the current object of a class.

8.

Can You Prevent A Class From Overriding?

Answer»

YES. You can prevent a class from overriding in C# by USING the sealed keyword; and in VB by using NotInheritable keyword.

Yes. You can prevent a class from overriding in C# by using the sealed keyword; and in VB by using NotInheritable keyword.

9.

Is It Possible To Execute Two Catch Blocks?

Answer»

No. Whenever, an exception occurs in your PROGRAM, the correct catch block is EXECUTED and the CONTROL goes to the finally block.

No. Whenever, an exception occurs in your program, the correct catch block is executed and the control goes to the finally block.

10.

Can You Inherit Private Members Of A Class?

Answer»

No, we cannot INHERIT PRIVATE MEMBERS of a CLASS because private members are accessible only to that class and not OUTSIDE that class.

No, we cannot inherit private members of a class because private members are accessible only to that class and not outside that class.

11.

You Declare An Overridden Method To Be Static If The Original Method Is Not Static?

Answer»

No. TWO VIRTUAL METHODS MUST have the same SIGNATURE.

No. Two virtual methods must have the same signature.

12.

Can You Allow A Class To Be Inherited, But Prevent A Method From Being Overridden In C#?

Answer»

YES. By Declaring the CLASS public and MAKING the method sealed.

Yes. By Declaring the class public and making the method sealed.