skip to content

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 pageshow

explore

questions

page 2 of 2

In C# 11 and later, what does the file modifier restrict on a type, and why do source generators declare their helper types with it?

level: middleimportance: nice to knowfreq 20%

basics

~20 s

A 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.

open as a page

In C# 9 and later, can an override of Notification Clone() return EmailNotification, and what limits apply to covariant returns?

level: middleimportance: nice to knowfreq 25%

basics

~20 s

Yes. 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.

open as a page

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?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

C# 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.

open as a page

showing 31–33 of 33