Skip to content

C# Feature – nameof

The nameof operator returns the unqualified string name of a symbol at compile time. Safer than magic strings.

C# 6 (2015)

throw new ArgumentNullException("userName");
throw new ArgumentNullException(nameof(userName));
  • nameof(Type.Member) returns just “Member”. Use for argument names, property changed events, logging, and mapping.