nameof expression in .net framework 4

前端 未结 5 604
小鲜肉
小鲜肉 2020-12-03 07:05

\"nameof\" expression is introduced in Visual Studio 2015 and c# 6

nameof (C# and Visual Basic Reference)

How can u use it or write a similar method in older

5条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:51

    nameOf - Gets resolved at Compiletime - if you decompile, you will see that the compiler just translated the classname (without the Namespace(!)) into a constant string instead. So be aware!

    If you want to get a classe's name use typeof() or GetType() to get the specific (maybe derived) type at Runtime and read the value of
    the .Name-Property in .net < C#6.

    Read more at MSDN

提交回复
热议问题