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 responses to “#VS2015 – C# 6, nameof operator to get variables, types or members names”

  1. […] #VS2015 – C# 6, nameof operator to get variables, types or members names by El Bruno […]

    Like

Leave a reply to #VS2015 – C#6, using Expression Bodied Members … hell on earth !!! | El Bruno Cancel reply

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading