查找传递给函数的变量名 [英] Finding the variable name passed to a function

查看:34
本文介绍了查找传递给函数的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我用下面的示例解释我的问题:

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);

当我将变量 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()

有什么办法吗?

推荐答案

**否**我不这么认为。

**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.

如果有帮助,您可以定义一个名为NamedParameter的新类,该类具有Name和Param属性。然后,您将该对象作为参数传递。

If it helps, you could define a new class called NamedParameter with attributes Name and Param. You then pass this object around as parameters.

这篇关于查找传递给函数的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆