Monday, 18 May 2020

Interview Questions on CSharp Basics

CSharp Basics Questions and Answers

1. Can You Allow A Class To Be Inherited, But Prevent A Method From Being Overridden In C#?
Ans :Yes. By Declaring the class public and making the method sealed.

2. You Declare An Overridden Method To Be Static If The Original Method Is Not Static?
Ans :No. Two virtual methods must have the same signature.

3. Can You Inherit Private Members Of A Class?
Ans :No, we cannot inherit private members of a class because private members 
are accessible only to that class and not outside that class

4. Is It Possible To Execute Two Catch Blocks?
Ans :No. Whenever, an exception occurs in your program, 
 the correct catch block is executed and the control goes to the finally block.

5. Can You Prevent A Class From Overriding?
Ans :Yes. You can prevent a class from overriding in C# by using the sealed keyword;

6. What Is 'this' Pointer?
Ans :'this' pointer refers to the current object of a class.

7. Can 'this' Be Used Within A Static Method?
Ans :No.

8. Is It Possible For A Class To Inherit The Constructor Of Its Base Class?
Ans :No. A class cannot inherit the constructor of its base class.

9. What's The Difference Between The 'ref' And 'out' Keywords?
Ans :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.

10. Difference Between Const, Readonly And Static Readonly In C# ?
Ans :
1)Constant variables are declared and initialized at compile time. The value can't be changed after words.
2)Readonly variables will be initialized only from the non-static constructor of the same class.
3)Static Readonly variables will be initialized only from the static constructor of the same class.

You can find more blogs on our website: Trigya Technologies

No comments:

Post a Comment

Steps to resolve VAPT Issues

    1. Error: Web Parameter Tampering Resolution:   Add attribute " enableViewStateMac = " false " " inside  <pages...