C# Tips

C# Quiz Test 101

1. Which of the followings is not allowed in C# as access modifier?

public
friend
internal
protected

2. In the C# code below, what is this[int i]?

class MyClass
{
// ...

public string this[int i]
{
get{ return arr[i];}
set{ arr[i] = value; }
}
}

Property
Event
Indexer
Delegate

3. Which of the following C# keywords has nothing to do with multithreading?

async
await
sealed
lock

4. Find an invalid expression among the following C# Generics examples.

class A where T : class, new()
class A where T : struct, IComparable
class A where T : class, struct
class A where T : Stream where U : IDisposable

5. new keyword in C# is used to creat new object from the type. Which of the followings is not allowed to use new keyword?

Class: var a = new Class1();
Interface : var a = new IComparable();
Struct : var a = new Struct1();
C# object : var a = new object();

6. In the example below, button1 is an object of Button class in WinForms. Which one is a wrong expression as a click event handler?

button1.Click += new System.EventHandler(button1_Click);
button1.Click += delegate { MessageBox.Show("Click"); };
button1.Click += delegate(EventArgs e){MessageBox.Show("Click");};
button1.Click += (s, e) => MessageBox.Show("Click");

7. In the C# example below, which using statement is wrong?

1
2
3
4

8. What is the output of this C# code?

int? i = 8 >> 5;
int? j = i > 0 ? i : null;
var a = j ?? int.MinValue;
Console.WriteLine(a);

1
null
0
-2147483648

9. Find a correct statement about C# exception

C# exception occrs at compile time
C# exception occrs at linking time
C# exception occrs at JIT compile time
C# exception occrs at run time

10. Find an invalid Main() method prototype, which is entry point in C#?

public static void Main()
public static int Main()
public static void Main(string[] s)
public static long Main(string[] args)