
C# Language Essentials
Nullable types, generics, attributes, extension methods, type casting, advanced enums
1What is the correct syntax to declare a nullable int variable in C#?
What is the correct syntax to declare a nullable int variable in C#?
Відповідь
In C#, a nullable type for value types is declared with the '?' suffix after the type (int?, bool?, DateTime?). This allows value types to have a null value, which is not possible by default. Nullable types are useful to represent the absence of value in database or API scenarios.
2Which operator allows providing a default value if a nullable variable is null?
Which operator allows providing a default value if a nullable variable is null?
Відповідь
The null-coalescing operator '??' returns the left-hand value if it is not null, otherwise the right-hand value. This operator is very useful for handling nullable types and avoiding NullReferenceException. There is also the '??=' operator for conditional assignment introduced in C# 8.
3What is the difference between casting with '(Type)' and 'as' in C#?
What is the difference between casting with '(Type)' and 'as' in C#?
Відповідь
The cast '(Type)object' throws an InvalidCastException if the conversion fails, while the 'as' operator returns null on failure. The 'as' operator only works with reference types and nullable value types. Use 'as' to avoid exceptions in cases where null is an acceptable value.
How to check if a nullable variable has a value before using it?
What is the syntax to declare a generic class with a type constraint?
+12 питань зі співбесід
Інші теми співбесід .NET
C# Basics
LINQ & Delegates
ASP.NET Core Fundamentals
ASP.NET Core Request Lifecycle
Configuration & Settings
Application Lifecycle
Dependency Injection
Entity Framework Core
Minimal APIs
Web API Development
Async in ASP.NET Core
Authentication & Authorization
HttpClient & Networking
JSON Serialization
Entity Framework Core Advanced
C# Advanced Features
Clean Architecture
Logging, Monitoring & Observability
Unit Testing & xUnit
Integration Testing
Docker & Containerization
NuGet Package Management
Memory Management & GC
Reactive Programming
Async/await & Patterns
.NET Design Patterns
Performance Optimization
Security & Best Practices
SignalR & Real-time
Microservices Architecture
Опануй .NET для наступної співбесіди
Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.
Почни безкоштовно