• +91 9723535972
  • info@interviewmaterial.com

CSharp Interview Questions and Answers

CSharp Interview Questions and Answers

Question - 11 : -   How can you sort the elements of the array in descending order?

Answer - 11 : -   By calling Sort() and then Reverse() methods. 

Question - 12 : -   What’s the .NET collection class that allows an element to be accessed using a unique key?

Answer - 12 : - HashTable.

Question - 13 : -   What class is underneath the SortedList class?

Answer - 13 : - A sorted HashTable. 

Question - 14 : - Will the finally block get executed if an exception has not occurred?­

Answer - 14 : - Yes.

Question - 15 : -   What’s the C# syntax to catch any possible exception?

Answer - 15 : -   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 - 16 : -   Can multiple catch blocks be executed for a single try statement?

Answer - 16 : -   No.  Once the proper catch block processed, control is transferred to the finally block (if there are any). 

Question - 17 : -   Explain the three services model commonly know as a three-tier application.

Answer - 17 : - Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources). 

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

Answer - 18 : - 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 - 19 : - How is a property designated as read-only?

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

Question - 20 : -
  What is hiding in CSharp ?

Answer - 20 : -   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”  } }


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners