Intermediate C#
Q52 / 100

What is the difference between lock and Monitor in C#?

Correct! Well done.

Incorrect.

The correct answer is B) lock is syntactic sugar for Monitor.Enter/Monitor.Exit, providing a simpler way to synchronize access

B

Correct Answer

lock is syntactic sugar for Monitor.Enter/Monitor.Exit, providing a simpler way to synchronize access

Explanation

lock (obj) { } compiles to Monitor.Enter(obj, ref lockTaken); try { ... } finally { Monitor.Exit(obj); }. Monitor offers TryEnter with timeout.

Progress
52/100