Showing posts with label C# Interview Questions. Show all posts
Showing posts with label C# Interview Questions. Show all posts

C# Interview Questions and answer


1.Can we declare multiple catch blocks to be execute?

Ans:No,Multiple catch blocks can't be execute  Once the proper catch code executed, the control is transferred to the finally block, and then the code that follows the finally block gets executed.


2.What is Constructor?
Ans:A constructor is a member function in a class that has the same name as its class. The constructor is automatically invoked whenever an object class is created. It constructs the values of data members while initializing the class.

3.Explain Jagged array
Ans:The Array which has elements of type array is called jagged Array. The elements can be of different dimensions and sizes. We can also call jagged Array as an Array of arrays.

4.What is ref and Out Parameter in c#?
Ans:Both are used to pass value as a reference.An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method.

5.What is Serialization?
Ans:When we want to transport an object through a network, then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should implement ISerialize Interface. De-serialization is the reverse process of creating an object from a stream of bytes.

6.Can we use This command with Static method?
Ans:We can't use 'This' in a static method because we can only use static variables/methods in a static method.

7.Give difference between const and read only.
Ans:Constant variables are declared and initialized at compile time. The value can't be changed afterward. Read-only is used only when we want to assign the value at run time.

8.What is an Interface?
Ans:An Interface is an abstract class which has only public abstract methods, and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.

9.What is Sealed class?
Ans:We create sealed classes when we want to restrict the class to be inherited. Sealed modifier used to prevent derivation from a class. If we forcefully specify a sealed class as base class, then a compile-time error occurs.

10.What is Method Overloading?
Ans:Method overloading is creating multiple methods with the same name with unique signatures in the same class. When we compile, the compiler uses overload resolution to determine the specific method to be invoke.

11.What is Difference between Array and Array List?
Ans:In an array, we can have items of the same type only. The size of the array is fixed when compared. To an arraylist is similar to an array, but it doesn't have a fixed size.

12.What is Difference between Interface ans Abstract class?
Ans.Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.

13.What is Delegate?
Ans:Delegates are same are function pointers in C++, but the only difference is that they are type safe, unlike function pointers. Delegates are required because they can be used to write much more generic type-safe functions.

14.Difference between Method Overloading and Method Overriding?
Ans:In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures.

15.What is Difference between struct and class?
Ans:Structs are value-type variables, and classes are reference types. Structs stored on the Stack causes additional overhead but faster retrieval. Structs cannot be inherited.





Jagged Array

What is Jagged Array? Jagged array is called as "array of arrays". when you need a data inside your array element at that time you...