{"id":2873,"date":"2013-06-27T15:10:00","date_gmt":"2013-06-27T15:10:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2013\/06\/27\/seeing-function-return-values-in-the-visual-studio-2013-debugger\/"},"modified":"2022-07-19T06:45:47","modified_gmt":"2022-07-19T14:45:47","slug":"seeing-function-return-values-in-the-visual-studio-2013-debugger","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/seeing-function-return-values-in-the-visual-studio-2013-debugger\/","title":{"rendered":"Seeing function return values in the Visual Studio 2013 debugger"},"content":{"rendered":"<p>You asked, and we have listened. Seeing return values for functions is something that many .NET developers wanted, and voted heavily for on the <a href=\"http:\/\/visualstudio.uservoice.com\/\">Visual Studio uservoice site<\/a>. This feature exists already for C++ code and the good news is that with the latest version of Visual Studio, it\u2019s here and you\u2019ll be able to use it for your .NET code too.<\/p>\n<p>This new feature allows you to examine the return value of a function when the developer steps over or out of a function during your debugging session. This is especially useful when the returned value is not stored in a local variable. Consider the following nested function example **Foo(Bar()); **in this example you can now examine the return value(s) from Bar and Foo, when you step over that line.<\/p>\n<p>The return value(s) get displayed in the \u201cAutos Windows\u201d (Debug->Windows->Autos) and you can also use the pseudo variable \u201c$ReturnValue\u201d in the Watch and\/or Immediate window to fetch the last function\u2019s return value.<\/p>\n<p>\u00a0<\/p>\n<p>Here are some steps for you to try it out in action:<\/p>\n<p>1) Create a new C# Console Application<\/p>\n<p>2)\u00a0Copy the following code to your program.cs<\/p>\n<pre>01 class Program\n02      {\n03          static void Main()\n04          {\n05              int result = Multiply(Five(), Six());\n06          }\n07  \n08          private static int Multiply(int num1, int num2)\n09          {\n10              return (num1 * num2);\n11          }\n12  \n13          private static int Five()\n14          {\n15              return(5);\n16          }\n17  \n18          private static int Six()\n19          {\n20              return (6);\n21          }\n22      }\n<\/pre>\n<p>\u00a0<\/p>\n<p>3) Put a breakpoint in line # 05 \u2013 [<em>int** result =Multiply(Five(), Six());<\/em>] and run it<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/06\/2146.3.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>4)\u00a0Run the program (F5)<\/p>\n<p>\u00a0<\/p>\n<p>5) When the program breaks step-over the function (F10)<\/p>\n<p>Observe:<\/p>\n<p>6)\u00a0As this example was nested functions, you are able to see all the return values in the autos window<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/06\/2068.6.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>7)\u00a0\u00a0You can also use the last returned value in your immediate window<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2013\/06\/8357.7.png\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u00a0<\/p>\n<p>Note that if a function returns a struct, it will not be displayed in the Autos window with the exceptions of enums and structs that have exactly one field which is the size of a pointer (i.e. structs with the same characteristics as enums).<\/p>\n<p>In closing, we are really happy to bring this capability to you and as always your feedback is welcome in the <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vsdebug\/threads\">diagnostics forum<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You asked, and we have listened. Seeing return values for functions is something that many .NET developers wanted, and voted heavily for on the Visual Studio uservoice site. This feature exists already for C++ code and the good news is that with the latest version of Visual Studio, it\u2019s here and you\u2019ll be able to [&hellip;]<\/p>\n","protected":false},"author":85,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,225],"tags":[],"class_list":["post-2873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-git"],"acf":[],"blog_post_summary":"<p>You asked, and we have listened. Seeing return values for functions is something that many .NET developers wanted, and voted heavily for on the Visual Studio uservoice site. This feature exists already for C++ code and the good news is that with the latest version of Visual Studio, it\u2019s here and you\u2019ll be able to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/85"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=2873"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/2873\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=2873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=2873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=2873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}