C# Interview Questions


What is C#?

C# is a programming language designed by Microsoft. It is loosely based on C/C++, and bears a striking similarity to Java in many ways. Microsoft describe C# as follows:
"C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++. C# is firmly planted in the C and C++ family tree of languages, and will immediately be familiar to C and C++ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C++."

What is OOPS language?

An object oriented programming language based on 3 major concepts
·        Encapsulation
·        Polymorphism
·        Inheritance

Encapsulation
          It is a programming mechanism that binds together code and the data it manipulates and that keeps both safe from outside interference. For example class, which holds the methods and data as a private or public member. If it declare private then the members can’t access from outside.

Polymorphism
          The ability to work differently in different instance without losing basic characteristics known as Polymorphism. For example
·        Operator Overloading
·        Method  Overloading
·        Method  Overriding
Inheritance
          It is the process by which objects of one class acquire the properties of object of another class. It provides the idea of reusability means use the same code rather create it again. It based on concept of specialization.

What is a Class?

            Class is a user defines data type, which contains data and code to manipulate the data. It relates with reference type.

What is an Object?

            Object is a basic runtime variable of a class. It fulfils the objective for what a class is declaring. It relates with reference type.

What is a Method?

            Methods are the subroutines that manipulate the data defined by the class to do some operation.

What is a Constructor?

            Constructor is the special methods of a class whose name is same as class name. Its primary objective is to initializes an object when it assigned. There are 3 type of constructor like

            *Default Constructor (having no arguments)
          *Parameterize Constructor (having one or more arguments)
          *Copy Constructor (it copies an object to another object)
It use 2 operator to allocate and release memory
·        New: - For allocation of memory.
·        Delete: - For release memory.

What is type conversion and casting?

            Type conversion is 2 types
                   *Implicit type conversion (Automatic type conversion)
                   *Explicit type conversion (Type casting)
What is Jagged Array?

            Array of arrays is called jagged array.

What is method overloading?

            Two or more method within the same class can share the same name as long as their parameter declarations are different and this process refers to method overloading. 


 What is constructor overloading?

            If more than one constructor present in a same class for construct objects in a variety of ways then that process known as constructor overloading.

What is operator overloading?

            When a same operator used for different purpose then that mechanism is known as operator overloading like
·        “+” (for adding 2 numbers and concatenate 2 strings)
It relates with static polymorphism.

What is property?

Properties are nothing but natural extension of data fields. They are usually known as 'smart fields' in C# community.

What is Indexer?

            Indexer is a member of class that hold only objects just like an array and we access a Product from the indexer that can access by its index position.

Who build the object of derived class?
            Both the constructor partly constructs the object of derived class. The   base class constructor construct the base class portion of the constructor and the derived class constructor construct the derived class portion of the constructor.
[NB: The base class constructor always invokes first]

How to call a base class constructor within a derived class?

            Syntax: <derived class constructor_name> (parameter_list): base(parameter_list)
                   {
                             //   Body of derived constructor
}
What is Name Hiding?

            If a derived class defines a member that has same name as a member in its base class then the member in the base class in hidden within the derived class and for this the compiler show a warning. To prevent the warning the derived class member must be proceed by the “new” key word.
            Example:
                   Class A{ public int i=0;}
                   Class B:A{new int i ;}

And in order to access the hidden name
          Example:
                   Class A{public int i=0;}
                   Class B{     new int i ;
                                      Public B(int a,int b)
                                                {
                                                          Base.i=a;
                                                          i=b;
}
}
What is virtual method and method overriding?

            A virtual method is a method that is declared as virtual in a base class and redefined in one or more its derived classes.
          The process of redefining a virtual method inside a derived class is called method overriding. And this mechanism based on runtime polymorphism.


What is abstract class?

            An abstract class is a class which is always declared as base class and used by its derived classes. So object is never created for it.

What is abstract method?

            An abstract method is a method which declared within an abstract base class and must be override by its derived class.

What is sealed (class)?

            Sealed is a keyword using for prevent a class to inherited by other classes.

What is an object class?

             Object class is a base class of all classes and all the features are available to its derived classes.


What is boxing and unboxing?

            Boxing and unboxing are the type conversion mechanisms.
Boxing: it is used to convert a value type to object type.
Unboxing: it is used to convert an object type to values type.

What is Interface?

            An Interface is a purely logical construct that describes functionality without describing implementation and the body is declare within the class which is implement it.

  What is delegate?

A delegate is an object that can refer to a method. When a delegate refers to a method the method can be called through that delegate. It supports the feature of multicasting.

 What is multicasting?

            Multicasting is the ability to create an invocation list of method that will automatically call when a delegate is invoked.

 What is an Event?

An event is 'a member that enables an object or class to provide notifications.
           
What is Namespace?

            Namespace a container which may contain other namespace, classes, Interfaces, structures and delegates.

 What is region?

            The region is a directive, use to hide codes to avoid the confusion.

 What is GC class?

            GC class encapsulated the C# Garbage Collection facility, which helps to release the oldest pieces of allocated memory which are can not release by automatic garbage collection mechanism. It is a sealed class.

What is ICloneable Interface?

            ICloneable Interface is a Interface which helps to make a copy of an invoking object. It has 2 methods for coping mechanism
                   *Deep coping (by using clone () method)
                   *Shallow coping (by using memberwise clone () method)
 Deep coping -- It create a separate copy of an object.
           Shallow coping -- It create a reference to the object rather create a separate copy.

 What is Multithreading?

            Multithreading is a mechanism by which one can do more than one job at same time, which relates with multitasking.

 What is Synchronization?

            Synchronization is a feature of multithreading which allows the execution of threads in a certain and well defined ways. It is very useful when more than one thread needs access to a shared resource.
          Synchronization solve this problem by using
·        Lock
·        Monitor
What is hashing?

            Hashing is a mechanism used by Hashtable data structure to store information.
It relates with reference type.

What is a static constructor?

A constructor for a class, rather than instances of a class. The static constructor is called when the class is loaded.

No comments:

Post a Comment