问题描述
让我用下面的例子来解释我的问题:
公共字符串ExampleFunction(字符串变量){
返回的东西;
}字符串WhatIsMyName =Hello World的;
字符串Hello = ExampleFunction(WhatIsMyName);
当我通过变量WhatIsMyName的例子功能,我希望能够拿到原始变量名的字符串。也许是这样的:
Variable.OriginalName.ToString()
有没有办法做到这一点?
否我不这么认为。
您使用的变量名是为了您的方便和可读性。编译器并不需要它和放大器;只是夹头出来,如果我没有记错。
如果有帮助,你可以定义一个名为NamedParameter带属性的名称和参数新类。然后,您身边传递这个对象作为参数。
Let me use the following example to explain my question:
public string ExampleFunction(string Variable) {
return something;
}
string WhatIsMyName = "Hello World"';
string Hello = ExampleFunction(WhatIsMyName);
When I pass the variable "WhatIsMyName" to the example function, I want to be able to get a string of the original variables name. Perhaps something like:
Variable.OriginalName.ToString()
Is there any way to do this?
No.I don't think so.
The variable name that you use is for your convenience and readability. The compiler doesn't need it & just chucks it out if I'm not mistaken.
If it helps, you could define a new class called NamedParameter with attributes Name and Param. You then pass this object around as parameters.
这篇关于找到传递给函数在C#中的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!