Classes and Hierarchies
Classes, constructors, inheritance, interfaces, access modifiers and extension members: how C# models a domain. Interviewers ask about virtual dispatch and interface design.
on this pageshowhide
explore
- Fields and Properties5 questions
- Constructors and Initialization6 questions
- Overriding and Hiding5 questions
- Explicit and Default Implementations6 questions
- Visibility Levels6 questions
- Extension Members5 questions
questions
page 2 of 2In C# 11 and later, what does the file modifier restrict on a type, and why do source generators declare their helper types with it?
basics
~20 sA type declared with the file modifier (C# 11) is visible only inside the source file that declares it. Two files can each declare a file-local Formatter without a name clash, which is why source generators use it for helper types.
In C# 9 and later, can an override of Notification Clone() return EmailNotification, and what limits apply to covariant returns?
basics
~20 sYes. Since C# 9 an override may return a more derived reference type, so callers holding an EmailNotification get EmailNotification without a cast. It needs .NET 5 or later and works for methods and read-only properties, not value types or setters.
In C# 14, how does an extension block add an IsEmpty property and a static member to IEnumerable<T>, and how does it relate to classic extension methods?
basics
~20 sC# 14 lets a static class declare extension(IEnumerable<T> source) { ... } blocks holding extension properties, methods, operators and static members. They compile to static methods, and an instance method in a block matches a classic this method exactly.
showing 31–33 of 33