CSharp Interview Questions and Answers
Question - 51 : -
Normal
0
f
Answer - 51 : -
Normal
0
false
false
false
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block
Question - 52 : - What does assert() do?
Answer - 52 : - In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
Question - 53 : - What is the difference between public, static, and void?
Answer - 53 : - Public declared variables or methods are accessible anywhere in the application. Static declared variables or methods are globally accessible without creating an instance of the class. Static member are by default not globally accessible it depends upon the type of access modified used. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created. And Void is a type modifier that states that the method or variable does not return any value.
Question - 54 : - How can you describe object-oriented concepts in detail?
Answer - 54 : -
C# is an object-oriented programming language that supports 4 OOP concepts.
- Encapsulation: defines the binding together code and the data and keeps it safe from any manipulation done by other programs and classes. It is a container that prevents code and data from being accessed by another program that is defined outside the container.
- Abstraction: this concept of object-oriented protects everything other than the relevant data about any created object in order to increase efficiency and security within the program.
- Inheritance: Inheritance is applied in such a way where one object uses the properties of another object.
- Polymorphism: is a feature that allows one interface to act as a base class for other classes. This concept is often expressed as a "single interface but multiple actions".
Question - 55 : - Explain how code gets compiled in C#?
Answer - 55 : -
It takes 4 steps to get a code to get compiled in C#. Below are the steps:
- First, compile the source code in the managed code compatible with the C# compiler.
- Second, combine the above newly created code into assemblies.
- Third, load the CLR.
- Last, execute the assembly by CLR to generate the output.
Question - 56 : - How you can explain the use of ‘using’ statements in C# in detail.
Answer - 56 : -
The using statement is used to control the usage of one or more resources that are being used within the program. The resources are continuously consumed and released. The main function of this statement is to manage unused resources and release them automatically. Once the object is created which is using the resource and when you are done you make sure that the object’s dispose method is called to release the resources used by that object, this is where using statements works well.
For example:
using (MyResource abc = new MyResource())
{
abc.program();
}
Gets translated to,
MyResource abc= new MyResource();
try
{
myRes.program();
}
finally
{
// Check for a null resource.
if (abc!= null)
// Call the object's Dispose method.
((IDisposable)abc).Dispose();
}
Question - 57 : - Describe the C# dispose of the method in detail.
Answer - 57 : - Dispose of the method: The disposeof() method releases the unused resources by an object of the class. The unused resources like files, data connections, etc. This method is declared in the interface called IDisposable which is implemented by the class by defining the interface IDisposable body. Dispose method is not called automatically, the programmer has to implement it manually for the efficient usage of the resources.
Question - 58 : - Explain in detail the finalize method in C#?
Answer - 58 : - Finalize method- The finalize () method is defined in the object class which is used for cleanup activities. This method is generally called by the garbage collector whenever the reference of any object is not used for a long time. Garbage collector frees that managed resources automatically but if you want to free the unused resources like filehandle, data connection, etc., then you have to implement the finalize method manually.
Question - 59 : - How you can define the exception handling in C#?
Answer - 59 : -
An exception is a raised problem that may occur during the execution of the program. Handling exceptions offers a simple way to pass the control within the program whenever an exception is raised. C# exceptions are handled by using 4 keywords and those are try, catch, finally, throw.
- try: a raised exception finds a particular block of code to get handled. There is no limit on the number of catch blocks that you will use in your program to handle different types of exception raised.
- catch: you can handle the raised exception within this catch block. You can mention the steps that you want to do to solve the error or you can ignore the error by suppressing it by the code.
- Finally: irrespective of the error, if you still want some set of instructions to get displayed then you can use those statements within the finally block and it will display it on the screen.
- throw: you can throw an exception using the throw statement. It will display the type of error you are getting.
Syntax:
try {
//exception handling starts with try block
} catch( ExceptionName ea1 ) {
// errors are handled within the catch block
} catch( ExceptionName e2 ) {
// more catch block
} catch( ExceptionName eN ) {
// more catch block to handle multiple exception raised
} finally {
// last block of the exception handling
}
Question - 60 : - Explain the concept of Destructor in detail. Explain it with an example.
Answer - 60 : -
A destructor is a member that works just the opposite of the constructor. Unlike constructors, destructors mainly delete the object. The destructor name must match exactly with the class name just like a constructor. A destructor block always starts with the tilde (~) symbol.
Syntax:
~class_name()
{
//code
}
A destructor is called automatically:
- when the program finishes its execution.
- Whenever a scope of the program ends that defines a local variable.
- Whenever you call the delete operator from your program.