C# & CLR Internals (50 Qs)•Part 1: Core Language, CLR & Memory Architecture (1 - 10)
What is the difference between `Task.Run` vs. `Task.Yield` vs. `ValueTask<T>`?
senior LevelSystem Design
In Simple Words:
Task.Run: Queues CPU-bound work to run on a backgroundThreadPoolthread. Never use for I/O-bound operations.Task.Yield: Forces the current method to yield execution asynchronously, re-queuing the continuation back to the dispatcher.ValueTask<T>: A struct-based task representation that avoids heap allocation when an asynchronous method completes synchronously (e.g. returning cached results).