• +91 9971497814
  • info@interviewmaterial.com

CSharp Interview Questions Answers

Question 1 :   What is hiding in CSharp ?

Answer 1 :   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 2 : Can you create enumerated data types in C#?

Answer 2 : Yes.

Question 3 : Can multiple catch blocks be executed?

Answer 3 :   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 4 : Will finally block get executed if the exception had not occurred?

Answer 4 :   Yes.

Question 5 : How do you generate documentation from the C# file commented properly with a command-line compiler?

Answer 5 : Compile it with a /doc switch.

Question 6 : What's the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?

Answer 6 :   A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

Question 7 : Can you declare a C++ type destructor in C# like ~MyClass()?

Answer 7 :   Yes, but what's the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up,  plus, it introduces additional load on the garbage collector.

Question 8 : How would you implement inheritance using VB.NET/C#?

Answer 8 : When we set out to implement a class using inheritance, we must first start with an existing class from which we will derive our new subclass. This existing class, or base class, may be part of the .NET system class library framework, it may be part of some other application or .NET assembly, or we may create it as part of our existing application. Once we have a base class, we can then implement one or more subclasses based on that base class. Each of our subclasses will automatically have all of the methods, properties, and events of that base class ? including the implementation behind each method, property, and event. Our subclass can add new methods, properties, and events of its own - extending the original interface with new functionality. Additionally, a subclass can replace the methods and properties of the base class with its own new implementation - effectively overriding the original behavior and replacing it with new behaviors. Essentially inheritance is a way of merging functionality from an existing class into our new subclass. Inheritance also defines rules for how these methods, properties, and events can be merged. In VB.NET we can use implements keyword for inheritance, while in C# we can use the sign ( :: ) between subclass and baseclass

Question 9 : Speaking of Boolean data types, what's different between C# and C/C++?

Answer 9 :   There's no conversion between 0 and false, as well as any other number and true, like in C/C++.

Question 10 : How is a property designated as read-only?

Answer 10 :   In C# Private DataType mPropertyName; public returntype PropertyName {       get{                         //property implementation goes here                         return mPropertyName;             }             // Do not write the set implementation }

CSharp Contributors

Rajeev Katiyar

Share your email for latest updates

Name:
Email:

Our partners