C# Tips

C# Quiz Test 201

1. The following C# code is using C# Generics. Which is an incorrect explanation?

T t = default(T);

If T is int type, variable t has 0
If T is a reference type, variable t has null
If T is string type, variable t has an empty string
If T is bool type, variable t has false

2. C# / .NET supports various built-in data structures. Which of the following data structures does not exist as built-in?

Array
D-Array
Binary Tree
Stack
Linked List

3. Which of the following interfaces should be implemented to use LINQ to Objects?

IEnumerable
IEnumerable
ICollection
ICollection

4. What is the result of the following C# code?

null will be displayed in console
4 will be displayed in console
Will cause compile error
Runtime exception will occur

5. Find an invalid example of using C# var

var a = 3.141592;
var a = null;
var a = db.Stores;
var a = db.Stores.Single(p => p.Id == 1);

6. In the following C# example, variable a is string. Find one that either is wrong or returns a different result.

a = a ?? "";
a = a == null ? "" : a;
a = (a is null) ? "" : a;
if (a == null) a = "";

7. When you want to provide other resources for other cultures or languages, which assembly should you create?

Public Assembly
Private Assembly
Shared Assembly
Satellite Assembly

8. Which of the followings does not allow you to use C# static keyword?

(Method) static void Run() {}
(Property) static int Prop {get; set;}
(Field) static int _field;
(Class) static class MyClass {}
(Constructor) static MyClass() {}
(Destructor) static ~MyClass() {}
(Event) static event EventHandler evt;

9. In C#, what is similar to C++ function pointer?

Event
Interface
Delegate
Method

10. Which of the following C# methods is not valid? (method body elided)

public void Set(dynamic o) {}
public dynamic Get() {}
private var GetData() {}
protected override int[] A() {}