Monday, July 13, 2009

C# InterviewQuestions- Part 9

81. why we use the ref keyword?
a ) If you want to pass a parameter by reference you should use the keyword ref

82. If an out parameter is not assigned a value with in the body of the function does that method complile?
a ) No. it won't compile

83. How can you make write a read only property?
a ) A property can made a read only by omitting the set accessor from the property defination.

84. When a static constructor is executed?
a ) It is executed when the class is loaded.

85. How many preprocessor directives exists in c#?
a ) They are #define, #undef, #if, #elif, #else, #endif, #error, #warning, #region, #endregion, #pragma etc

86. When an instance constructor is executed?
a ) It is executed when an instance is created.

87. Where you can assign values to a read only field?
a ) We can assign inside a constructor

88. Why we use the sixeof operator?
a ) If we want to know the size of any data type you can use sizeof operator.

89. What are the disadvantages of distructors in c#?
a ) 1. They are non deterministic. means there is no way to know when an object's destructor will actually execute.
2. Implementation of destructor delays the final removal of an object from memory. means objects that have destructors are removed in 2 passes. in the 1st pass only the destructor will be called with out removing object and then the 2nd pass removes the object, which is time taking and which may effect the performance.

90. What is the default access modifier of an interface members?
a) public

Thursday, July 2, 2009

C# InterviewQuestions- Part 8

Interview Questions
-----------------------------

71. Can we declare an abstract method in non abstract class?
a ) No. it can declared only in abstract classes

72. Can we use static or virtual keywords to an abstract method?
a ) No

73. Can an interface extend a class?
a ) No. it can’t extend classes.

74. Is it necessary that the direct base class of a derived class must be at least as accessible as the derived class itself?
a ) Yes.

75. What is the keyword that is used to invoke the constructor method of the super class?
a ) It is the keyword “base”.

76. What is an enumeration?
a ) An enumeration is a user-defined integer type which provides a way for attaching names to numbers.

77. What is boxing?
a ) Conversion of value type to object type (reference type) is known as boxing

78. What is unboxing?
a ) Conversion of object type to value type is known as unboxing.

79. What are the categories of variables that are automatically initialized to their default values?
a ) They are
1. Static variables
2. Instance variables
3. Array elements

80. What is the scope of a variable?
a ) Scope of a variable is the region of code with in which the variable can be accessed.