Home
C-Sharp
Interview FAQs

Show

FAQs of level

Typed memory locations for storing values. Also known as a field or a local variable.
1. When the class itseft is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.
A delegate method encapsulate a reference to a method.
A delegate that has multiple handler assigned to it. Each assigned hander (Method) is called.
C# supports the keyword "this" which is a reference to the object that called the method. The "this" reference is available within all the member method and always refers to the current instance. It is normally used to distinguish between the local and instance variables that have the same name. The "this" reference is a hidden reference passed to every non-static method of a class. Consider the code -

class temp {
int x, y;
public void setXY(int x, int y) {
this.x =x;
this.y =y; } }

In the assignment statement, this.x and this.y refer to the class member named y and y whereas simple x and y refer to the parameter of the setXY() method.

If your class declares a static constructor, you are guaranteed that the static constructor will run before any instance of your class is created.

Eg. -
public class Time { private static string Name;
static Time () { Name = "Time"; } }

Notice that there is no access modifier before the static constructor. Access modifiers are not allowed on static constructors. In addition, because this is a static member method, you can not access non-static variables and so Name must be declared a static member variable.

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.

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.

There are two reasons C# doesn't have this feature.

1 - it is possible to get nearly the same effect by having a class-level static, and adding method statics would require increased complexity.
2 - method level statics are somewhat notorious for causing problems when code is called repeatedly or from multiple threads, and since the definitions are in the methods, it's harder to find the definitions.

A sealed class cannot be inherited. A sealed class is used primarily when the class contains static members. Note that a struct is implicitly sealed; so they cannot be inherited.
PreviousDisplaying 13 of 25Next
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*