| Can you change the value of a variable while debugging a C# application? |
| Yes. If you are debugging via Visual Studio.NET, just go to Immediate window. |
|
|
|
|
|
| Where is the output of TextWriterTraceListener redirected? |
| To the Console or a text file depending on the parameter passed to the constructor. |
|
|
|
|
|
| What anonymous methods in C# 2.0? |
| C# 2.0 provides a new feature called Anonymous Methods, which allow you to create inline un-named ( i.e. anonymous ) methods in your code, which can help increase the readability and maintainability of your applications by keeping the caller of the method and the method itself as close to one another as possible. This is akin to the best practice of keeping the declaration of a variable, for example, as close to the code that uses it. |
|
|
|
|
|
| How destructors works in C# ? |
| The garbage collector maintains a list of objects that have a destructor. This list is updated every time such an object is created or destroyed.
When an object on this list is first collected, it is placed in a queue with other objects waiting to be destroyed. After the destructor executes, the garbage collector collects the object and updates the queue, as well as its list of destructible objects. |
|
|
|
|
|
| What is the difference between const and static readonly? |
| The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.
In the static readonly case, the containing class is allowed to modify it only
-in the variable declaration (through a variable initializer)
-in the static constructor (instance constructors, if it's not static)
static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.
Instance readonly fields are also allowed.
Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference. |
|
|
|
|
|
|