C# Tips

C# Quiz Test 301

1. Which of the following statements is not valid to create new object in C#?

var a = new Int32();
var a = new String();
var a = new IComparable();
var a = new [] {0};

2. If you run C# executable file multiple times, multiple processes are created. If you want to have only one application process even if you launch multiple times, what can you use?

Semaphore
Mutex
Critical Section
C# lock

3. Which of the following operators cannot use operator overloading?

operator ++
operator &
operator ||
operator true

4. In multithread programming, which of the followings is not using Thread Pool?

BackgroundWorker class
Asynchronous delegate
Thread class
Task class

5. Class A has [Serializable()] attribute. When is [Serializable] checked?

[Serializable()]
class A { }

At C# compile time
At CLR runtime
At JIT compile time
At Linking

6. The followings are some examples of integer arrays. Which expression is not valid in C#?

int[] a = new int[10];
int[][] c = new int[10][];
int[][][] cc = new int[10][2][];
int[,] b = new int[10, 2];
int[, , ,] d = new int[10, 2, 2, 2];

7. Which of the following statements is true about C# anonymous type?

Anonymous type can add new property once it is created
Anonymous type can add an event
You can use a delegate for a method in anonymous type
Anonymous type is an immutable type

8. What is the result of variable a and b?

var a = 5L == 5.0F;
var b = 24L / 5 == 24 / 5d;

a=true, b=true
a=true, b=false
a=false, b=true
a=false, b=false

9. When defining a class using C# Generics, which of the followings is invalid?

class MyClass where T : struct
class MyClass where T : class
class MyClass where T : IComparable
class MyClass where T : MyBase
All of the above are correct

10. Which of the following statements is incorrect about C# delegate?

C# delegate supports multicast
C# delegate is considered as a technical basis of C# event
C# delegate can be used when passing a reference to a method
C# delegate can not use +=, -= operators