Interview Tips Interview Tips, Interview Questions and Answers

3Mar/100

C# interview questions and answers

I need to restrict a class by creating only one object throughout the application. How can I achieve this?
We can declare the constructor of the class as either protected or as private

int? d = 1; Type testType = d.GetType(); will result…
NOTE: This is objective type question, Please click question title for correct answer.

How can you make your machine shutdown from your program?
Process.Start("shutdown", "-s -f -t 0");

What is the use of unsafe keyword in C#?
In C# the value can be directly referenced to a variable, so there is no need of pointer. Use of pointer sometime crashes the application. But C# supports pointer, that means we can use pointer in C#.

The use of pointer in C# is defined as a unsafe code. So if we want to use pointer in C# the pointer must be present in the body of unsafe declaration. But pointer does not come under garbage collection.

Example:-

unsafe
{
int a, *b;
a = 25;
b = &a;
Console.WriteLine("b= {0}",b);//returns b= 25
}

What is difference between var and Dynamic ?
Var word was introduced with C#3.5(specifically for LINQ) while dynamic is introduced in C#4.0. variables declared with var keyword will get compiled and you can have all its related methods by intellisense while variables declared with dynamic keyword will never get compiled. All the exceptions related to dynamic type variables can only be caught at runtime.

What is dynamic keyword ?
Its newly introduced keyword of C#4.0. To indicate that all operations will be performed runtime.

What will happen if you declare a variable named "checked" with any data type?
Compiler will throw an error as checked is a keyword in C# So It cannot be used as variable name. Checked keyword is used to check the overflow arithmetic checking.

What are anonymous methods?
Anonymous methods are another way to declare delegates with inline code except named methods.

Restrictions of yield in try-catch.
While using yield keyword, mainly two restrictions are observed.
First is , we can’t use yield in finally.
Second is , we can’t place yield keyword in the catch block if try contains more than one catch blocks.

With yield break statement, control gets …
NOTE: This is objective type question, Please click question title for correct answer.

What first action compiler will take on detection of iterator ?
As soon as compiler will detect iterator, it will automatically generate current, MoveNext and Disposemethods of the IEnumerator or IEnumerator(T) type.

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.

18Feb/100

C# Interview Questions and Answers

1) The C# keyword ?int? maps to which .NET type?

  1. System.Int16

  2. System.Int32

  3. System.Int64

  4. System.Int128

2) Which of these string definitions will prevent escaping on backslashes in C#?

  1. string s = #?n Test string?;

  2. string s = ??n Test string?;

  3. string s = @?n Test string?;

  4. string s = ?n Test string?;

3) Which of these statements correctly declares a two-dimensional array in C#?

  1. int[,] myArray;

  2. int[][] myArray;

  3. int[2] myArray;

  4. System.Array[2] myArray;

4) If a method is marked as protected internal who can access it?

  1. Classes that are both in the same assembly and derived from the declaring class.

  2. Only methods that are in the same class as the method in question.

  3. Internal methods can be only be called using reflection.

  4. Classes within the same assembly, and classes derived from the declaring class.

5) What is boxing?

a) Encapsulating an object in a value type.

b) Encapsulating a copy of an object in a value type.

c) Encapsulating a value type in an object.

d) Encapsulating a copy of a value type in an object.

6) What compiler switch creates an xml file from the xml comments in the files in an assembly?

  1. /text

  2. /doc

  3. /xml

  4. /help

7) What is a satellite Assembly?

  1. A peripheral assembly designed to monitor permissions requests from an application.

  2. Any DLL file used by an EXE file.

  3. An assembly containing localized resources for another assembly.

  4. An assembly designed to alter the appearance or ?skin? of an application.

8) What is a delegate?

  1. A strongly typed function pointer.

  2. A light weight thread or process that can call a single method.

  3. A reference to an object in a different process.

  4. An inter-process message channel.

9) How does assembly versioning in .NET prevent DLL Hell?

  1. The runtime checks to see that only one version of an assembly is on the machine at any one time.

  2. .NET allows assemblies to specify the name AND the version of any assemblies they need to run.

  3. The compiler offers compile time checking for backward compatibility.

  4. It doesn?t.

10) Which ?Gang of Four? design pattern is shown below?

public class A {

    private A instance;

    private A() {

    }

    public
static A Instance {

        get

        {

            if ( A == null )

                A = new A();

            return instance;

        }

    }

}

  1. Factory

  2. Abstract Factory

  3. Singleton

  4. Builder

31Dec/090

Types of Interview Questions

Questioning Toolkit

Apart from the many kinds of questions mentioned above, there are other types of questions that we can add to our questioning toolkit.

Essential questions are asked to probe the real meaning of the issues that confront us. These questions make us realize our purpose in life and define the realities of living. At times, we tend toask questions that are not totally significant or applicable to what is being talked about. These are called irrelevant questions. For inquiries that seem to go beyond human understanding and exploration, they are referred to as unanswerable questions.

Inventive questions are asked out of the need to find out more about an incomplete satisfaction to knowledge or learning something new. Sometimes, we become challenged or provoked with some questions being asked. We refer to them as provocative questions and this type is closely similar to irreverent questions which can be offensive or rude and aggressive at some point.

General Types of Questions

Probably, all sorts of questions can be broadly classified into open ended and closed ended questions as these are the basic ways of formulating questions. Open ended questions invite a speaker to tell more about what is being asked or talked about while closed ended questions are asked to gather specific information and for verification. Some closed ended questions are also called specific questions which are used to collect or confirm basic facts.

For a deeper exploration of an issue or a subject matter, we ask probing questions that can either be open or closed type and relevant only to the topic. In order to gain creative answers from situational issues, hypothetical questions are used.

Reflective questions are intended to contemplate on what the speaker has said or felt and also to check for understanding. Leading questions, from the term itself, are used to lead us to agree or disagree with thespeaker without thinking of personal opinions. This is best used for persuasion and making quick decisions.

Socratic Type of Questioning

The famous Socrates is well known for contributing knowledge in the aspect of questioning. To date, educators have been benefiting from Socratic manner of asking questions. There are five basic types of Socratic questions and these are factual, convergent, divergent, evaluative, and combination.
Factual questions require answers based on factual knowledge. Answers for this type are straightforward which are either right or wrong. Convergent questions utilize a person’s comprehension, analysis, and the ability to put answers into application.

Divergent questions allow us to exercise creativity in our answers and think out of the box. As answers to this type may be subjective, correctness is subjective as well depending on logic and rational reasoning. Evaluative type involves a higher level of cognitive function such as decision making or drawing out judgment. Lastly, combination questions are a mixture of the other four types.