List out some of the exceptions in C#?
Answer:
Below are some of the exceptions in C# -
- NullReferenceException
- ArgumentNullException
- DivideByZeroException
- IndexOutOfRangeException
- InvalidOperationException
- StackOverflowException etc.
Result: 105 questions
List out some of the exceptions in C#?
Answer:
Below are some of the exceptions in C# -
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.
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.
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.
What are the types of delegates in C#?
Answer:
Below are the uses of delegates in C# -
What are the three types of Generic delegates in C#?
Answer:
Below are the three types of generic delegates in C# -
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.
Can we use delegates for asynchronous method calls in C#?
Answer:
Yes. We can use delegates for asynchronous method calls.
What are the uses of delegates in C#?
Answer:
Below are the list of uses of delegates in C# -
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;
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;
What is the difference between “as” and “is” operators in C#?
Answer:
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);
What is the difference between CType and Directcast in C#?
Answer:
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.
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.
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");
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");
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};
Which are the loop types available in C#?
Answer:
Below are the loop types in C# -
For
While
Do.. While
© 2017 QuizBucket.org