Wednesday 19 September 2018

 C# Interview Questions with Answers

Q -1) What is an Object and a Class?

Ans: A Class is an encapsulation of properties and methods that are used to represent a real-time                  entity. It is a data structure that brings all the instances together in a single unit.

Q -2) What are the fundamental OOP concepts?
Ans: The four fundamental concepts of Object Oriented Programming are:
  • Encapsulation – The Internal representation of an object is hidden from the view outside object’s definition. Only the required information can be accessed whereas the rest of the data implementation is hidden.
  • Abstraction – It is a process of identifying the critical behavior and data of an object and eliminating the irrelevant details.
  • Inheritance – It is the ability to create new classes from another class. It is done by accessing, modifying and extending the behavior of objects in the parent class.
  • Polymorphism – The name means, one name, many forms. It is achieved by having multiple methods with the same name but different implementations.
Q -3) What is Managed and Unmanaged code?

Ans: Managed code is a code which is executed by CLR (Common Language Runtime) i.e all application code based on .Net Platform. It is considered as managed because of the .Net framework which internally uses the garbage collector to clear up the unused memory.

Unmanaged code is any code that is executed by application runtime of any other framework apart from .Net. The application runtime will take care of memory, security and other performance operations.

Q -4) What are the different types of classes in C#?
Ans: The different types of class in C# are:

  • Partial class – Allows its members to be divided or shared with multiple .cs files. It is denoted by the keyword Partial.
  • Sealed class – It is a class which cannot be inherited. To access the members of a sealed class, we need to create the object of the class.  It is denoted by the keyword Sealed.
  • Abstract class – It is a class whose object cannot be instantiated. The class can only be inherited. It should contain at least one method.  It is denoted by the keyword abstract.
  • Static class – It is a class which does not allow inheritance. The members of the class are also static.  It is denoted by the keyword static. This keyword tells the compiler to check for any accidental instances of the static class.
Q -5) Explain Code compilation in C#.
Ans: There are four steps in code compilation which include:

  • Compiling the source code into Managed code by C# compiler.
  • Combining the newly created code into assemblies.
  • Loading the Common Language Runtime(CLR).
  • Executing the assembly by CLR.
Q -6) What is the difference between Virtual method and Abstract method?
Ans: Virtual method must always have a default implementation. However, it can be overridden in the derived class, though not mandatory. It can be overridden using override keyword.
An Abstract method does not have an implementation. It resides in the abstract class. It is mandatory that the derived class implements the abstract method. An override keyword is not necessary here though it can be used.

Q -7) Explain Namespaces in C#.
Ans: They are used to organize large code projects. “System” is the most widely used namespace in C#. We can create our own namespace and use one namespace in another, which are called Nested Namespaces.
They are denoted by the keyword “namespace”.

No comments:

Post a Comment

What is ArrayList in C#?

What is ArrayList in C#? The ArrayList collection is similar to the Arrays data type in C#. The biggest difference is the dynamic natur...