Language specifics Flashcards
Explain the difference between Task and Thread in .NET
Thread class is a .NET representation of operation system threads, it allows low-level management of threads, where Task is an abstraction for an operation that can be run asynchronously or in parallel. Task execution does not always utilizes threads (like when it represents IO operation) and does not map to thread 1 to 1 - it uses thread pooling to reuse threads instead of creating new ones.
Explain when to use Finalize vs Dispose?
Finalize is a method that Garbage Collector executes before terminating an object so we don’t have a control over exact moment when it executes, so we can’t rely on finalization to free some unmanaged resources. Dispose, however, even while it has language support of using block, is not guaranteed to be executed, because it is supposed to be executed manually.
It’s better to use disposable most of the time and protect yourself with compiler and IDE warnings if disposable object is not disposed.
What’s the difference between RyuJIT and Roslyn?
Roslyn compiler compiles C# code into Intermediate Language code, when RyuJIT is just-in-time compiler that compiles IL code into native code on demand in runtime.
What is Boxing and Unboxing?
Boxing is a conversion of a value type instance into reference of object class which is made to unify type system and let developers pass values to methods that require object. Unboxing is a reverse conversion to original value type.