#VS2015 – C# 6, nameof operator to get variables, types or members names

Hola!

Sometime ago I wrote about the new feature in C# 6 which allow us to use String Interpolation instead of String.Format(). In C# 6 we also found a new cool operator: nameof. This new operator allows us to get in string the name of a variable, or a type or a member. If you think in exception handling scenarios or dynamic generation this is very useful.

So, let’s see this in action, with a sample console Project and a custom class.

In the Console Main(), the program Display the name of a couple of variables and also the name of a couple of operations (custom and system). The console Output is this one

References

– El Bruno, String Interpolation https://elbruno.com/2015/04/20/vs2015-string-interpolation-vs-string-format-your-team-will-love-you/

– MSDN nameof, https://msdn.microsoft.com/en-us/library/dn986596.aspx

Saludos @ Madrid

/El Bruno

2 thoughts on “#VS2015 – C# 6, nameof operator to get variables, types or members names

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.