nameof

What is the purpose of nameof?

南楼画角 提交于 2019-11-26 09:15:39
问题 Version 6.0 got a new feature of nameof , but I can\'t understand the purpose of it, as it just takes the variable name and changes it to a string on compilation. I thought it might have some purpose when using <T> but when I try to nameof(T) it just prints me a T instead of the used type. Any idea on the purpose? 回答1: What about cases where you want to reuse the name of a property, for example when throwing exception based on a property name, or handling a PropertyChanged event. There are