是否有可能(以及如何)在方法中匿名使用声明变量?没有在代码本身中使用他们的名字。我必须声明它们的名称(用于可读性+调试)。但我想不使用它们。C#中的匿名变量用法?
我希望它可以像通过反射列出一个类的所有方法名称。
例子:
private static void TestVars()
{
string dsjkfd4378957439898 = "hello world";
string hgf43789 = "hello world2";
string ntgdklf4589 = "hello world3";
// more strings
// print names of ALL string variables above (and their values)
// like this but without knowing the names of the string variables
Console.WriteLine("dsjkfd4378957439898" + " = " + dsjkfd4378957439898);
// ...
}
请详细说明您的问题。很难理解你问什么。 – Reniuz 2014-09-24 06:31:06
你的目标是什么? – 2014-09-24 06:31:18
为什么不使用所需类型或对象的一组元素,如果您将使用不同的... – blfuentes 2014-09-24 06:33:06