获取变量名称为字符串? [英] get name of variable as string?

查看:76
本文介绍了获取变量名称为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在黑暗中拍摄,因为我知道C#没有宏,因此不能
有一个字符串操作符,但我知道你可以得到
枚举为字符串,所以也许你可以用普通的

变量(比如int)做同样的事情。可能吗? int.ToString()

将int的值作为字符串返回,而不是名称,所以我认为'b $ b'想要''不''。


Zytan

Shot in the dark, since I know C# doesn''t have macros, and thus can''t
have a stringizer operator, but I know that you can get the name of
enums as strings, so maybe you can do the same with an ordinary
variable (like an int) somehow. Is it possible? int.ToString()
returns the value of the int as a string, not the name, so I am
thinking ''no''.

Zytan

推荐答案

" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** **@d57g2000hsg.googlegr oups.com ...
"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.com...

在黑暗中拍摄,因为我知道C#没有宏,所以不能

有一个stringizer操作符,但我知道你可以将

枚举的名称作为字符串,所以也许你可以用普通的
$以某种方式b $ b变量(如int)。可能吗? int.ToString()

将int的值作为字符串返回,而不是名称,所以我认为'b $ b'想要''不''。
Shot in the dark, since I know C# doesn''t have macros, and thus can''t
have a stringizer operator, but I know that you can get the name of
enums as strings, so maybe you can do the same with an ordinary
variable (like an int) somehow. Is it possible? int.ToString()
returns the value of the int as a string, not the name, so I am
thinking ''no''.



你想要做什么,你需要这种行为?

What are you attempting to do that you need this behavior?


你想要做的是做反射。 GoogleC#Reflection。另请参阅

查看System.Reflection命名空间。


" Zytan"写道:
What you want to do is called Reflection. Google "C# Reflection". Also take
a look at the System.Reflection namespace.

"Zytan" wrote:

在黑暗中拍摄,因为我知道C#没有宏,因此不能

有一个stringizer操作符,但我知道你可以将

枚举的名称作为字符串,所以也许你可以用普通的

变量(比如int)来做同样的事情。可能吗? int.ToString()

将int的值作为字符串返回,而不是名称,所以我认为'b $ b'想要''不''。


Zytan

Shot in the dark, since I know C# doesn''t have macros, and thus can''t
have a stringizer operator, but I know that you can get the name of
enums as strings, so maybe you can do the same with an ordinary
variable (like an int) somehow. Is it possible? int.ToString()
returns the value of the int as a string, not the name, so I am
thinking ''no''.

Zytan




" Bill Butler" < qw **** @ asdf.com在留言中写道

news:xdZOh.112519

"Bill Butler" <qw****@asdf.comwrote in message
news:xdZOh.112519


这篇关于获取变量名称为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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