Watch window 中的 $ReturnValue 在 VS2015 中不起作用
$ReturnValue in Watch window doesn't work in VS2015
在 VS2013 中,我们可以通过检查名为 $ReturnValue
的 Watch window 条目来查看方法的 return 值。这在 VS2015 中似乎不起作用。
例如我制作了一个新的控制台应用程序,其中包含以下代码:
using System;
namespace ReturnInspector
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Number: {0}", Method1());
}
public static int Method1()
{
return Method2(1000); //A
} //B
private static int Method2(int i)
{
return i + 42;
}
}
}
如果我在行 //A
上放置一个断点,那么一旦断点,F10 跳转到行 //B
,Watch window 中的 $ReturnValue
项显示“1042”在 VS2013 中,但在 VS2015 中显示为:
error CS0103: The name '$ReturnValue' does not exist in the current context
请注意,Autos 和 Locals windows 正确地说:
ReturnInspector.Program.Method2 returned 1042
有谁知道 Watch window 功能中的 $ReturnValue
是否在 VS2015 中被删除了?
确保您已在工具 >> 选项 >> 调试 >> 使用旧版 C# 和 VB 表达式求值器 选项中选中。
来自MSDN:
You must have the legacy expression evaluators turned on for $ReturnValue to be recognized (Tools / Options / Debugging / Use the legacy C# and VB expression evaluators). Otherwise, you can use $ReturnValue1.
在 VS2019 社区中,它与 $ReturnValue1 一起使用
在 VS2013 中,我们可以通过检查名为 $ReturnValue
的 Watch window 条目来查看方法的 return 值。这在 VS2015 中似乎不起作用。
例如我制作了一个新的控制台应用程序,其中包含以下代码:
using System;
namespace ReturnInspector
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Number: {0}", Method1());
}
public static int Method1()
{
return Method2(1000); //A
} //B
private static int Method2(int i)
{
return i + 42;
}
}
}
如果我在行 //A
上放置一个断点,那么一旦断点,F10 跳转到行 //B
,Watch window 中的 $ReturnValue
项显示“1042”在 VS2013 中,但在 VS2015 中显示为:
error CS0103: The name '$ReturnValue' does not exist in the current context
请注意,Autos 和 Locals windows 正确地说:
ReturnInspector.Program.Method2 returned 1042
有谁知道 Watch window 功能中的 $ReturnValue
是否在 VS2015 中被删除了?
确保您已在工具 >> 选项 >> 调试 >> 使用旧版 C# 和 VB 表达式求值器 选项中选中。
来自MSDN:
You must have the legacy expression evaluators turned on for $ReturnValue to be recognized (Tools / Options / Debugging / Use the legacy C# and VB expression evaluators). Otherwise, you can use $ReturnValue1.
在 VS2019 社区中,它与 $ReturnValue1 一起使用