Question statement:
Determine the name of the variable or parameter passed to the function. For example, given the following code:
How do we get the name "MyINPUT" in two cases?
<code class="language-csharp">var myInput = "input"; var nameOfVar = GETNAME(myInput); // ==> nameOfVar 应该等于 "myInput" void testName([Type?] myInput) { var nameOfParam = GETNAME(myInput); // ==> nameOfParam 应该等于 "myInput" }</code>
C# 6.0 Pre -plan:
Using the MEMBERINFOGetting class, you can retrieve the name of any member provided. The following is the implementation method:C# 6.0 and higher version scheme:
C# 6.0 The Nameof operational symbol introduced in the search parameters, variables, and attribute names. The following is the implementation method:
The above is the detailed content of How Can I Get the Name of a C# Variable or Parameter at Runtime?. For more information, please follow other related articles on the PHP Chinese website!