Keyword

Result: 105 questions

List out some of the exceptions in C#?

Answer:

Below are some of the exceptions in C# -

  • NullReferenceException
  • ArgumentNullException
  • DivideByZeroException
  • IndexOutOfRangeException
  • InvalidOperationException
  • StackOverflowException etc.
View

Explain Generics in C#?

Answer:

Generics in c# is used to make the code reusable and which intern decreases the code redundancy and increases the performance and type safety. 
Namespace – “System.Collections.Generic” is available in C# and this should be used over “System.Collections” types.

View

Explain object pool in C#?

Answer:

Object pool is used to track the objects which are being used in the code. So object pool reduces the object creation overhead.

View

What you mean by delegate in C#?

Answer:

Delegates are type safe pointers unlike function pointers as in C++. Delegate is used to represent the reference of the methods of some return type and parameters.

View

What are the types of delegates in C#?

Answer:

Below are the uses of delegates in C# -

  • Single Delegate
  • Multicast Delegate
  • Generic Delegate
View

What are the three types of Generic delegates in C#?

Answer:

Below are the three types of generic delegates in C# -

  • Func
  • Action
  • Predicate
View

What are the differences between events and delegates in C#?

Answer:

Main difference between event and delegate is event will provide one more of encapsulation over delegates. So when you are using events destination will listen to it but delegates are naked, which works in subscriber/destination model.

View

Can we use delegates for asynchronous method calls in C#?

Answer:

Yes. We can use delegates for asynchronous method calls.

View

What are the uses of delegates in C#?

Answer:

Below are the list of uses of delegates in C# -

  • Callback Mechanism
  • Asynchronous Processing
  • Abstract and Encapsulate method
  • Multicasting

 

View

What is Nullable Types in C#?

Answer:

Variable types does not hold null values so to hold the null values we have to use nullable types. So nullable types can have values either null or other values as well.

Eg: Int? mynullablevar = null;
View

Why to use “Nullable Coalescing Operator” (??) in C#?

Answer:

Nullable Coalescing Operator can be used with reference types and nullable value types. So if the first operand of the expression is null then the value of second operand is assigned to the variable. For example,

double? myFirstno = null;
double mySecno;
mySecno = myFirstno ?? 10.11;
View

What is the difference between “as” and “is” operators in C#?

Answer:

  • “as” operator is used for casting object to type or class.
  • “is” operator is used for checking the object with type and this will return a Boolean value.
View

Define Multicast Delegate in C#?

Answer:

A delegate with multiple handlers are called as multicast delegate. The example to demonstrate the same is given below

public delegate void CalculateMyNumbers(int x, int y);
int x = 6;
int y = 7;
CalculateMyNumbers addMyNumbers = new CalculateMyNumbers(FuncForAddingNumbers);
CalculateMyNumbers multiplyMyNumbers = new CalculateMyNumbers(FuncForMultiplyingNumbers);
CalculateMyNumbers multiCast = (CalculateMyNumbers)Delegate.Combine (addMyNumbers, multiplyMyNumbers);
multiCast.Invoke(a,b);
View

What is the difference between CType and Directcast in C#?

Answer:

  • CType is used for conversion between type and the expression.
  • Directcast is used for converting the object type which requires run time type to be the same as specified type.
View

 Is C# code is unmanaged or managed code?

Answer:

C# code is managed code because the compiler – CLR will compile the code to Intermediate Language.

View

Why to use lock statement in C#?

Answer:

Lock will make sure one thread will not intercept the other thread which is running the part of code. So lock statement will make the thread wait, block till the object is being released.

View

Explain Hashtable in C#?

Answer:

It is used to store the key/value pairs based on hash code of the key. Key will be used to access the element in the collection. For example,

Hashtable myHashtbl = new Hashtable();
myHashtbl.Add("1", "TestValue1");
myHashtbl.Add("2", "TestValue2");

 

View

How to check whether hash table contains specific key in C#?

Answer:

Method – “ContainsKey” can be used to check the key in hash table. Below is the sample code for the same –

Eg: myHashtbl.ContainsKey("1");
View

What is enum in C#?

Answer:

enum keyword is used for declaring an enumeration, which consists of named constants and it is called as enumerator lists. Enums are value types in C# and these can’t be inherited. Below is the sample code of using Enums

Eg: enum Fruits { Apple, Orange, Banana, WaterMelon};
View

Which are the loop types available in C#?

Answer:

Below are the loop types in C# -

For
While
Do.. While

View

© 2017 QuizBucket.org