nameof Operator

suggest change

Returns a string that represents the unqualified name of a variable, type, or member.

int counter = 10;
nameof(counter); // Returns "counter"
Client client = new Client();
nameof(client.Address.PostalCode)); // Returns "PostalCode"

The nameof operator was introduced in C# 6.0. It is evaluated at compile-time and the returned string value is inserted inline by the compiler, so it can be used in most cases where the constant string can be used (e.g., the case labels in a switch statement, attributes, etc…). It can be useful in cases like raising & logging exceptions, attributes, MVC Action links, etc…

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Operators:
* Syntax
* sizeof
* typeof
* nameof Operator

Table Of Contents
2 Operators
17 Regex
19 Arrays
21 Enum
22 Tuples
24 GUID
27 Looping
36 Casting
46 Methods
88 Events
92 Structs
104 Indexer
106 Stream
107 Timers
109 Threading
127 Caching
135 Pointers
147 C# Script