• +91 9971497814
  • info@interviewmaterial.com

CSharp Interview Questions Answers

Question 1 : C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

Answer 1 : Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it

Question 2 : Describe the accessibility modifier protected internal.

Answer 2 : It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).

Question 3 :  Can you store multiple data types in System.Array?

Answer 3 : No

Question 4 :   What is hiding in CSharp ?

Answer 4 :   Hiding is also called as Shadowing. This is the concept of Overriding the methods. It is a concept used in the Object Oriented Programming. E.g.  public class ClassA {  public virtual void MethodA() {   Trace.WriteLine("ClassA Method");  } } public class ClassB : ClassA {  public new void MethodA() {   Trace.WriteLine("SubClass ClassB Method");  } } public class TopLevel {  static void Main(string[] args) {   TextWriter tw = Console.Out;   Trace.Listeners.Add(new TextWriterTraceListener(tw));     ClassA obj = new ClassB();   obj.MethodA(); // Outputs “Class A Method"     ClassB obj1 = new ClassB();   obj.MethodA(); // Outputs “SubClass ClassB Method”  } }

Question 5 : Can you create enumerated data types in C#?

Answer 5 : Yes.

Question 6 : Are private class-level variables inherited?

Answer 6 : Yes,but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.

Question 7 : Can you allow class to be inherited, but prevent the method from being over-ridden?

Answer 7 : Yes, just leave the class public and make the method sealed.

Question 8 : Can you inherit multiple interfaces?

Answer 8 : yes

Question 9 : Can multiple catch blocks be executed?

Answer 9 :   No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

Question 10 : How do you inherit from a class in C#?

Answer 10 : Place a colon and then the name of the base class. Notice that it’s double colon in C++.

CSharp Contributors

Rajeev Katiyar

Share your email for latest updates


Our partners