Home >Backend Development >C++ >How Can I Retrieve the Original Variable Name Passed to a C# Function?
When using variable calls
<code class="language-csharp">public string ExampleFunction(string Variable) { return "something"; // 修正:添加返回值 } string WhatIsMyName = "Hello World"; string Hello = ExampleFunction(WhatIsMyName);</code>, we may want to get the name of the original variable, for example:
WhatIsMyName
ExampleFunction
<code class="language-csharp">Variable.OriginalName.ToString() // == "WhatIsMyName"</code>Although the original variable name cannot be obtained directly, the C# 3.0 and higher versions can use LAMBDA expressions to provide a solution:
Note:
This method depends on unspecified behavior and may not be compatible with the future version or other compilers of C#. It is only suitable for direct access variables. If the variables pass or conversion through any calculation or conversion, this method will fail. In addition, this technology is mainly used for reflection and code analysis, and it is not recommended to use in conventional code.The above is the detailed content of How Can I Retrieve the Original Variable Name Passed to a C# Function?. For more information, please follow other related articles on the PHP Chinese website!