Friday 18 September 2015

Job Interview C#.Net Interview Questions and Answers

81. Does C# support #define for defining global constants? 
No. If you want to get something that works like the following C code:
#define A 1
use the following C# code: class MyConstants
{
public const int A = 1;
}
Then you use MyConstants.A where you would otherwise use the A macro.
Using MyConstants.A has the same generated code as using the literal 1.

82. Does C# support templates? 
No. However, there are plans for C# to support a type of template known as a generic. These generic types have similar syntax but are instantiated at run time as opposed to compile time. You can read more about them here.

83. Does C# support parameterized properties? 
No. C# does, however, support the concept of an indexer from language spec. An indexer is a member that enables an object to be indexed in the same way as an array. Whereas properties enable field-like access, indexers enable array-like access. As an example, consider the Stack class presented earlier. The designer of this class may want to expose array-like access so that it is possible to inspect or alter the items on the stack without performing unnecessary Push and Pop operations. That is, Stack is implemented as a linked list, but it also provides the convenience of array access.
Indexer declarations are similar to property declarations, with the main differences being that indexers are nameless (the name used in the declaration is this, since this is being indexed) and that indexers include indexing parameters. The indexing parameters are provided between square brackets.

84. Does C# support C type macros? 
No. C# does not have macros. Keep in mind that what some of the predefined C macros (for example, __LINE__ and __FILE__) give you can also be found in .NET classes like System.Diagnostics (for example, StackTrace and StackFrame), but they'll only work on debug builds.

85. Can you store multiple data types in System.Array? 
No.

86. Is it possible to inline assembly or IL in C# code? 
No.

87. Can you declare the override method static while the original method is non-static? 
No, you cannot, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override

88. Does C# support multiple inheritance? 
No, use interfaces instead.

89. 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.

90. Can you 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.

More Questions & Answers:-

No comments:

Post a Comment