C# INTERVIEW QUESTIONS
by Venkatesan M
WHAT IS C-SHARP (C#)?
C# is a type-safe, managed and object oriented language, which is compiled by .Net framework for generating intermediate language (IL).
EXPLAIN THE FEATURES OF C#?
- Constructors and Destructors
- Passing Parameters
- XML Documentation and
LIST SOME OF THE ADVANTAGES OF C#?
- Easy to learn
- Object oriented
- Component oriented
- Part of .NET framework
WHAT ARE IDE’S PROVIDED BY MICROSOFT FOR C# DEVELOPMENT?
- Visual Studio Express (VCE)
- Visual Studio (VS)
- Visual Web Developer
EXPLAIN THE TYPES OF COMMENTS IN C#?
Below are the types of comments in C# –
- Single Line Comment Eg : //
- Multiline Comments Eg: /* */
- XML Comments Eg : ///
EXPLAIN SEALED CLASS IN C#?
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.
LIST OUT THE DIFFERENCES BETWEEN ARRAY AND ARRAYLIST IN C#?
- 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.
WHY TO USE “USING” IN C#?
“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.
EXPLAIN NAMESPACES IN C#?
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.
WHY TO USE KEYWORD “CONST” IN C#? GIVE AN EXAMPLE.
“Const” keyword is used for making an entity constant. We can’t reassign the value to constant.
Eg: const string _name = "Test";
WHAT IS THE DIFFERENCE BETWEEN “CONSTANT” AND “READONLY” VARIABLES IN C#?
- “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.
EXPLAIN “STATIC” KEYWORD IN C#?
- “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.
WHAT IS THE DIFFERENCE BETWEEN “DISPOSE” AND “FINALIZE” VARIABLES IN C#?
- 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.
HOW THE EXCEPTION HANDLING IS DONE IN C#?
- In C# there is a “try… catch” block to handle the error.
CAN WE EXECUTE MULTIPLE CATCH BLOCKS IN C#?
No. Once any exception is occurred it executes specific exception catch block and the control comes out.
WHY TO USE “FINALLY” BLOCK IN C#?
“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.
WHAT IS THE DIFFERENCE BETWEEN “FINALIZE” AND “FINALLY” METHODS IN C#?
- 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.
WHAT IS THE DIFFERENCE BETWEEN “THROW EX” AND “THROW” METHODS IN C#?
- “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.
CAN WE HAVE ONLY “TRY” BLOCK WITHOUT “CATCH” BLOCK IN C#?
Yes we can have only try block without catch block but we have to have finally block.
LIST OUT TWO DIFFERENT TYPES OF ERRORS IN C#?
Below are the types of errors in C# –
- Compile Time Error
- Run Time Error
January 29, 2019
May 26, 2018
May 26, 2018