Intermediate C# test (Intermediate)
30 questions · 35 minutes · Free
LINQ, async/await, generics and ASP.NET Core basics.
What it covers
- LINQ
- async/await and Tasks
- Generics and interfaces
- Delegates and events
- ASP.NET Core basics
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Backend
- Price: Free
Earn a certificate
The Intermediate C# test is one of the 6 tests of the .NET Developer: Intermediate 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 Intermediate 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 common mistake when working with ASP.NET Core dependency injection that can lead to unexpected behavior and thread-safety issues?
- Using a third-party container instead of the built-in container
- Registering a service as a singleton when it should be scoped
- Not registering a service in the dependency injection container
- Using constructor injection instead of property injection
Answer: B. Registering a service as a singleton when it should be scoped
Registering a service as a singleton when it should be scoped is a common mistake in ASP.NET Core dependency injection. This can lead to issues where the same instance is reused across different requests, potentially causing unexpected behavior and thread-safety problems. Scoped services should be created once per request, while singleton services are created once and shared across the entire application.
Which of the following best describes the appropriate use cases for LINQ to Objects compared to traditional loops?
- LINQ to Objects is better suited for querying databases, while traditional loops are more flexible for in-memory collections.
- LINQ to Objects is better suited for handling XML data, while traditional loops are more flexible for querying databases.
- LINQ to Objects is better suited for in-memory collections, while traditional loops are more flexible for complex, performance-critical operations.
- LINQ to Objects is better suited for asynchronous operations, while traditional loops are more flexible for synchronous operations.
Answer: C. LINQ to Objects is better suited for in-memory collections, while traditional loops are more flexible for complex, performance-critical operations.
LINQ to Objects is ideal for querying in-memory collections with concise and readable syntax. Traditional loops, on the other hand, offer more control and can be more efficient for certain operations, especially when dealing with large datasets or complex logic that LINQ might not handle as efficiently.
Which statement accurately describes the purpose of generics in C#?
- Generics allow the use of dynamic types at runtime, which provides flexibility but reduces type safety.
- Generics are used exclusively for defining abstract classes and are not applicable to interfaces or methods.
- Generics allow type parameters to be specified when creating classes, interfaces, and methods, enabling code reuse and type safety.
- Generics are primarily used for defining events and delegates, with limited applicability to other features in C#.
Answer: C. Generics allow type parameters to be specified when creating classes, interfaces, and methods, enabling code reuse and type safety.
Generics allow type parameters to be specified when creating classes, interfaces, and methods, enabling code reuse and type safety. This is a core concept in C# generics, as it allows developers to create flexible and reusable code that can work with any data type while maintaining type safety. Other options may be incorrect because they do not accurately describe the purpose of generics or may refer to other features such as inheritance or type constraints.
What is a key characteristic of LINQ deferred execution?
- The result of the query is not executed until the data is accessed.
- The query is executed only once, regardless of how many times the data is accessed.
- The query is executed asynchronously by default.
- The query is executed immediately when it is created.
Answer: A. The result of the query is not executed until the data is accessed.
LINQ queries use deferred execution, meaning that the query is not executed immediately when it is created. Instead, the query is executed when the data is accessed, such as during iteration or when a method like ToList() is called.
What happens when a LINQ to SQL query is written but not executed immediately?
- The query will be compiled into SQL and executed immediately.
- The query will execute immediately and return a list of results.
- The query will throw an exception if the database connection is not established.
- The query will not execute immediately and will instead return a queryable object that can be further processed before execution.
Answer: D. The query will not execute immediately and will instead return a queryable object that can be further processed before execution.
In LINQ to SQL, queries are not executed immediately when they are written. Instead, they return a queryable object that represents the query. Execution occurs when the results are enumerated (e.g., via a foreach loop or when calling methods like ToList()). This allows for further manipulation of the query before it is executed against the database.
Frequently asked questions
- How many questions are in the Intermediate C# test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate C# test cover?
- LINQ, async/await and Tasks, Generics and interfaces, Delegates and events, ASP.NET Core basics.
- Is the Intermediate C# test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate C# test?
- Intermediate, in Backend.