Advanced C# test (Advanced)
40 questions · 40 minutes · Free
CLR internals, performance, advanced async and architecture.
What it covers
- CLR, GC and memory
- Span and performance
- Advanced async and threading
- Reflection and source generators
- ASP.NET Core and EF Core in depth
Interview format
- Questions: 40 questions — 24 multiple choice, 12 multi-answer, 4 predict-the-output
- Time: 40 minutes, timed from the first question
- Difficulty: Advanced
- Skill area: Backend
- Price: Free
Earn a certificate
The Advanced C# test is one of the 6 tests of the .NET Developer: Advanced learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Advanced C# test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
What is a key optimization behavior of ValueTask<T> in asynchronous programming?
- ValueTask<T> cannot be used with the 'await' keyword.
- ValueTask<T> avoids unnecessary allocations by reusing a single instance for multiple asynchronous operations.
- ValueTask<T> is always boxed when used in asynchronous methods.
- ValueTask<T> is slower than Task<T> in most scenarios.
Answer: B. ValueTask<T> avoids unnecessary allocations by reusing a single instance for multiple asynchronous operations.
ValueTask<T> optimizes asynchronous operations by reusing a single instance, which reduces memory allocations compared to Task<T> that creates a new object for each operation. This makes ValueTask<T> more efficient in scenarios where asynchronous operations are frequently created and disposed of.
In an ASP.NET Core application, which of the following best describes how the middleware pipeline operates and how short-circuiting can be achieved?
- The middleware pipeline is executed in the order they are added to the pipeline, and short-circuiting can be done with a return statement.
- The middleware pipeline is executed in the order they are added to the pipeline, but short-circuiting is not supported.
- The middleware pipeline is executed in reverse order of registration, and exceptions are ignored unless explicitly handled.
- The middleware pipeline is executed in the order they are added to the pipeline, and short-circuiting can be done with a break statement.
Answer: A. The middleware pipeline is executed in the order they are added to the pipeline, and short-circuiting can be done with a return statement.
In ASP.NET Core, middleware components are executed in the order they are added to the pipeline. Short-circuiting can be achieved by returning from the middleware method, which prevents subsequent middleware from being executed. This is a common practice for handling requests early, such as in authentication or error handling middleware.
Which of the following statements correctly describes the safety of a slice operation on a Span<T> in C#?
- The slice operation is safe because it does not allow out-of-bounds access.
- The slice operation is only safe when used with arrays, not with Span<T>.
- The slice operation is not checked at runtime for safety.
- The slice operation is unsafe because it allows out-of-bounds access.
Answer: A. The slice operation is safe because it does not allow out-of-bounds access.
In C#, when using Span<T> slice operations, the runtime performs safety checks to ensure that the slice does not go out of bounds. This is a key feature of Span<T> that helps prevent memory corruption and ensures safe access to the underlying memory. The other options are incorrect because they either describe unsafe behavior, are not related to slice safety checks, or are not valid in the context of the question.
Which of the following statements accurately describes the memory allocation behavior of Span<T> in C#?
- Span<T> is allocated on the stack and does not require a heap allocation.
- Span<T> is always allocated on the heap like arrays.
- Span<T> can only be used with unmanaged types.
- Span<T> is a reference type and requires a heap allocation.
Answer: A. Span<T> is allocated on the stack and does not require a heap allocation.
Span<T> is designed to be allocated on the stack, which makes it more efficient for short-lived data. This is in contrast to arrays, which are always heap-allocated. However, it's important to note that Span<T> can also be used with stack-allocated memory through methods like Memory<T>.Stackalloc().
In the CLR, where is the method table stored, and how is it shared across instances of a type?
- The method table is stored in the stack and is destroyed when the method exits.
- The method table is stored in each instance of the type and is unique to that instance.
- The method table is stored in the module's metadata and is shared across all instances of the type.
- The method table is stored in the heap and is not shared across instances of the type.
Answer: C. The method table is stored in the module's metadata and is shared across all instances of the type.
In the CLR, the method table is a critical part of the type layout, and it is stored in the module's metadata. It is shared across all instances of the type because it contains metadata about the methods, properties, and other type information. This allows the runtime to efficiently locate and invoke methods without duplicating data for each instance. Other options may be incorrect because they might suggest incorrect storage locations or misunderstand how method tables are shared.
Frequently asked questions
- How many questions are in the Advanced C# test?
- 40 questions (24 multiple choice, 12 multi-answer, 4 predict-the-output), with 40 minutes to answer them.
- What does the Advanced C# test cover?
- CLR, GC and memory, Span and performance, Advanced async and threading, Reflection and source generators, ASP.NET Core and EF Core in depth.
- Is the Advanced C# test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Advanced C# test?
- Advanced, in Backend.