C# Assessment: Sample Questions | Bryq

Beginner
Intermediate
Advanced
These are three sample questions from Bryq’s C# assessment, a coding test for hiring C# developers, .NET developers and back-end engineers. The full assessment covers three levels: beginner, intermediate and advanced, from core syntax and object-oriented principles to memory management, performance and concurrency. Questions test both C# concepts and the ability to read code and predict its output, with four options and one correct answer each.
Beginner

Question

What does the following code print?

int a = 7;
int b = 2;
Console.WriteLine(a / b);

Select your answer

3

3.5

4

3.0

WHY IS THIS THE CORRECT ANSWER

When both operands are integers, C# performs integer division and discards the remainder, so 7 / 2 gives 3. To get 3.5, at least one operand must be a floating-point type, for example 7.0 / 2 or (double)a / b.

Intermediate

Question

What does the following code print?

struct Point { public int X; }

var p1 = new Point { X = 1 };
var p2 = p1;
p2.X = 5;
Console.WriteLine(p1.X);

Select your answer

1

5

0

A compile-time error

WHY IS THIS THE CORRECT ANSWER

Structs are value types, so assigning p1 to p2 copies the whole value. Changing p2.X only affects the copy. If Point were a class, both variables would refer to the same object and the output would be 5.

Advanced

Question

What does the following code print?

var list = new List<int> { 1, 2, 3 };
var query = list.Where(x => x > 1);
list.Add(4);
Console.WriteLine(query.Count());

Select your answer

3

2

4

An InvalidOperationException

WHY IS THIS THE CORRECT ANSWER

LINQ operators such as Where use deferred execution: the filter only runs when the query is enumerated, which happens here when Count() is called. By then the list contains 1, 2, 3 and 4, so three values match. Calling ToList() when defining the query would have captured the result straight away, giving 2.

Ready to see Bryq in action?

Start hiring based on real data.

Ready to see Bryq in action?

Start hiring based on

real data.

Ready to see Bryq in action?

Start hiring based on real data.