C# Feature – nameof
Overview
Section titled “Overview”The nameof
operator returns the unqualified string name of a symbol at compile time. Safer than magic strings.
Introduced In
Section titled “Introduced In”C# 6 (2015)
Before
Section titled “Before”throw new ArgumentNullException("userName");
throw new ArgumentNullException(nameof(userName));
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”nameof(Type.Member)
returns just “Member”. Use for argument names, property changed events, logging, and mapping.