Top Most .Net Interview Questions Part – 4
1.What happens when you encounter a continue statement inside the for loop?
The code for the rest of the loop is ignored,the control is transferred back to the beginning of the loop.
2.What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in the cases,where a lot of manipulation is done to the text. Strings are immutable,so each time it’s being operated on,a new instance is created.
3.Can multiple catch blocks be executed?
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.
4.What’s a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
5.How’s the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32),but also the version of the assembly.
6.What’s a satellite assembly?
When you write a multilingual or multi-cultural application in .NET,and want to distribute the core application separately from the localized modules,the localized assemblies that modify the core application are called satellite assemblies.
7.What does assert() do?
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.
8.Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose,allowing to fine-tune the tracing activities.
9.What are three test cases you should go through in unit testing?
Positive test cases (correct data,correct output),negative test cases (broken or missing data,proper handling),exception test cases (exceptions are thrown and caught properly).
10.How’s method overriding different from overloading?
When overriding,you change the method behaviour for a derived class. Overloading simply involves having a method with the same name within the class.
11.Can you declare the override method static while the original method is non-static?
No,you can’t,the signature of the virtual method must remain the same,only the keyword virtual is changed to keyword override..
12.Can we override private virtual methods?
No,moreover,you cannot access private methods in inherited classes,have to be protected in the base class to allow any sort of access.
13.Can we prevent your class from being inherited and becoming a base class for some other classes?
Yes,that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.
14.Why can’t we specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore,to prevent you from getting the false impression that you have any freedom of choice,you are not allowed to specify any accessibility,it’s public by default.
15.What’s the difference between an interface and abstract class?
In the interface all methods must be abstract,in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed,which is ok in abstract classes.
16.What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable,so each time it’s being operated on,a new instance is created.
17.What’s an abstract class?
A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
18.Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore,to prevent you from getting the false impression that you have any freedom of choice,you are not allowed to specify any accessibility,it’s public by default.
19.What’s the difference between an interface and abstract class?
In an interface class,all methods must be abstract. In an abstract class some methods can be concrete. In an interface class,no accessibility modifiers are allowed,which is ok in an abstract class.