C# INTERVIEW QUESTIONS
by Venkatesan M, on Nov 4, 2017 12:41:43 PM
Q1. WHAT IS C-SHARP (C#)?
Ans: C# is a type-safe, managed and object oriented language, which is compiled by .Net framework for generating intermediate language (IL).
Q2. EXPLAIN THE FEATURES OF C#?
- Constructors and Destructors
- Properties
- Passing Parameters
- Arrays
- Main
- XML Documentation and
- Indexers
Q3. LIST SOME OF THE ADVANTAGES OF C#?
- Easy to learn
- Object oriented
- Component oriented
- Part of .NET framework
Q4. WHAT ARE IDE’S PROVIDED BY MICROSOFT FOR C# DEVELOPMENT?
- Visual Studio Express (VCE)
- Visual Studio (VS)
- Visual Web Developer
Q5. EXPLAIN THE TYPES OF COMMENTS IN C#?
Ans: Below are the types of comments in C#:
- Single Line Comment Eg : //
- Multiline Comments Eg: /* */
- XML Comments Eg : ///
Q6. EXPLAIN SEALED CLASS IN C#?
Ans: Sealed class is used to prevent the class from being inherited from other classes. So “sealed” modifier also can be used with methods to avoid the methods to override in the child classes.
Q7. LIST OUT THE DIFFERENCES BETWEEN ARRAY AND ARRAYLIST IN C#?
Ans:
- Array stores the values or elements of same data type but arraylist stores values of different datatypes.
- Arrays will use the fixed length but arraylist does not uses fixed length like array.
Q8. WHY TO USE “USING” IN C#?
Ans: “Using” statement calls – “dispose” method internally, whenever any exception occurred in any method call and in “Using” statement objects are read only and cannot be reassignable or modifiable.
Q9. EXPLAIN NAMESPACES IN C#?
Ans: Namespaces are containers for the classes. We will use namespaces for grouping the related classes in C#. “Using” keyword can be used for using the namespace in other namespace.
Q10. WHY TO USE KEYWORD “CONST” IN C#? GIVE AN EXAMPLE.
Ans: “Const” keyword is used for making an entity constant. We can’t reassign the value to constant.
Eg: const string _name = "Test".
Q11. WHAT IS THE DIFFERENCE BETWEEN “CONSTANT” AND “READONLY” VARIABLES IN C#?
Ans:
- “Const” keyword is used for making an entity constant. We cannot modify the value later in the code. Value assigning is mandatory to constant variables.
- “readonly” variable value can be changed during runtime and value to readonly variables can be assigned in the constructor or at the time of declaration.
Q12. EXPLAIN “STATIC” KEYWORD IN C#?
Ans: “Static” keyword can be used for declaring a static member. If the class is made static then all the members of the class are also made static. If the variable is made static then it will have a single instance and the value change is updated in this instance.
Q13. WHAT IS THE DIFFERENCE BETWEEN “DISPOSE” AND “FINALIZE” VARIABLES IN C#?
Ans:
- Dispose: This method uses interface – “IDisposable” interface and it will free up both managed and unmanaged codes like – database connection, files etc.
- Finalize: This method is called internally unlike Dispose method which is called explicitly. It is called by garbage collector and can’t be called from the code.
Q14. HOW THE EXCEPTION HANDLING IS DONE IN C#?
Ans: In C# there is a “try… catch” block to handle the error.
Q15. CAN WE EXECUTE MULTIPLE CATCH BLOCKS IN C#?
Ans: No. Once any exception is occurred it executes specific exception catch block and the control comes out.
Q16. WHY TO USE “FINALLY” BLOCK IN C#?
Ans: “Finally” block will be executed irrespective of exception. So while executing the code in try block when exception is occurred, control is returned to catch block and at last “finally” block will be executed. So closing connection to database / releasing the file handlers can be kept in “finally” block.
Q17. WHAT IS THE DIFFERENCE BETWEEN “FINALIZE” AND “FINALLY” METHODS IN C#?
Ans:
- Finalize: This method is used for garbage collection. So before destroying an object this method is called as part of clean up activity.
- Finally: This method is used for executing the code irrespective of exception occurred or not.
Q18. WHAT IS THE DIFFERENCE BETWEEN “THROW EX” AND “THROW” METHODS IN C#?
Ans:
- “throw ex” will replace the stack trace of the exception with stack trace info of re throw point.
- “throw” will preserve the original stack trace info.
Q19. CAN WE HAVE ONLY “TRY” BLOCK WITHOUT “CATCH” BLOCK IN C#?
Ans: Yes we can have only try block without catch block but we have to have finally block.
Q20. LIST OUT TWO DIFFERENT TYPES OF ERRORS IN C#?
Ans: Below are the types of errors in C#:
- Compile Time Error.
- Run Time Error.