↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

8 things you probably didn’t know about C#

The post collects eight C# details that many developers may miss. It shows how some features work in practice, including indexers with params, string interning, enum extension methods, brace-only local scopes, static initialization order, and access rules for private fields between instances.

It also warns that exposing a value as IEnumerable does not stop callers from casting back to the underlying list, and points out that the C# language specification is already installed with Visual Studio. One extra note at the end lists related spec facts about atomic variable references, nullable booleans, and Conditional(“DEBUG”).

Reading notes
#

  • Indexers can accept params, so a class can offer both a single-key indexer and a multi-key version side by side.
  • Repeated string literals are folded into one interned instance at compile time.
  • Returning IEnumerable does not prevent callers from casting back to the underlying List.
  • Braces alone can create a nested scope for local variables.
  • Enums can be extended with extension methods.
  • The order of static field declarations can change program behavior.
  • One instance can read another instance’s private fields if both are the same class.
  • The C# language specification is available in the Visual Studio installation folder.