nameof expression in .net framework 4

前端 未结 5 614
小鲜肉
小鲜肉 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条回答
  •  旧时难觅i
    2020-12-03 07:56

    The nameof operator returns a string representation of the variable you have passed it so nameof(var1) will return "var1", its useful in avoiding code where we have to specificy variable names as strings like in argument exceptions.

    In previous versions you could achieve a similar effect using reflection, or expression trees.

提交回复
热议问题