Interview Tips Interview Tips, Interview Questions and Answers

28Feb/100

C# interview questions with answers

What are the different method parameter modifiers in C#?
out
ref
params

What are the different Iteration Constructs in C#?
for loop
foreach/in loop
while loop
do/while loop

What is the use of ?? operator in C#?
This operator allows you to assign a value to a nullable type if the retrieved value is in fact null.

What is the CIL representation of implicit and explicit keywords in C#?
The CIL representation is op_Implicit and op_Explicit respectively.

Which operators in C# provides automatic detection of arithmetic overflow and underflow conditions?
'checked' and 'unchecked' keywords provide automatic detection of arithmetic overflow and underflow conditions.

What is the use of stackalloc keyword in C#?
In an unsafe context it is used to allocate C# array directly on the stack.

Which keyword in C# is used to temporarily fix a variable so that its address may be found?
fixed keyword

What are the different C# preprocessor directives?
#region , #endregion :- Used to mark sections of code that can be collapsed.

#define , #undef :-Used to define and undefine conditional compilation symbols.

#if , #elif , #else , #endif :- These are used to conditionally skip sections of source code.

What is the use of GetInvocationList() in C# delegates?
GetInvocationList() returns an array of System.Delegate types, each representing a particular method that may be invoked.

C# delegate keyword is derived form which namespace?
C# delegate keyword is derived form System.MulticastDelegate.

What will be the length of string type variable which is just declared but not assigned any value?
As variable is not initialized and it is of reference type. So it's length will be null and it will throw a run time exception of "System.NullReferenceException" type, if used.