{"id":42,"date":"2014-07-28T07:32:48","date_gmt":"2014-07-28T07:32:48","guid":{"rendered":"http:\/\/mairwa.com\/wordpress\/?p=42"},"modified":"2014-07-28T07:32:48","modified_gmt":"2014-07-28T07:32:48","slug":"distinction-between-output-and-reference-parameter","status":"publish","type":"post","link":"http:\/\/mairwa.com\/wordpress\/?p=42","title":{"rendered":"Distinction between output and reference parameter"},"content":{"rendered":"<p>&gt;&gt;<strong>output parameter do not need to initialize before the passed to the method.it\u00a0must assign when before \u00a0exiting the method calling.<\/strong><\/p>\n<p>&gt;&gt;<strong>reference parameter must assign the before passed to the method. The reason is that passing the reference to an existing variable. If not assign works as unassigned variable.<\/strong><\/p>\n<p align=\"LEFT\">\/\/ Returning multiple output parameters.<\/p>\n<p align=\"LEFT\">static void FillTheseValues(out int a, out string b, out bool c)<\/p>\n<p align=\"LEFT\">{<\/p>\n<p align=\"LEFT\">a = 9;<\/p>\n<p align=\"LEFT\">b = &#8220;Enjoy your string.&#8221;;<\/p>\n<p align=\"LEFT\">c = true;<\/p>\n<p>}<\/p>\n<p>static void Main(string[] args)<\/p>\n<p align=\"LEFT\">{<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;***** Fun with Methods *****&#8221;);<\/p>\n<p align=\"LEFT\">&#8230;<\/p>\n<p align=\"LEFT\">int i; string str; bool b;<\/p>\n<p align=\"LEFT\">FillTheseValues(out i, out str, out b);<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;Int is: {0}&#8221;, i);<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;String is: {0}&#8221;, str);<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;Boolean is: {0}&#8221;, b);<\/p>\n<p align=\"LEFT\">Console.ReadLine();<\/p>\n<p>}<\/p>\n<p align=\"LEFT\">\/\/ Reference parameters.<\/p>\n<p align=\"LEFT\">public static void SwapStrings(ref string s1, ref string s2)<\/p>\n<p align=\"LEFT\">{<\/p>\n<p align=\"LEFT\">string tempStr = s1;<\/p>\n<p align=\"LEFT\">s1 = s2;<\/p>\n<p align=\"LEFT\">s2 = tempStr;<\/p>\n<p align=\"LEFT\">}<\/p>\n<p align=\"LEFT\">This method can be called as follows:<\/p>\n<p align=\"LEFT\">static void Main(string[] args)<\/p>\n<p align=\"LEFT\">{<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;***** Fun with Methods *****&#8221;);<\/p>\n<p align=\"LEFT\">&#8230;<\/p>\n<p align=\"LEFT\">string str1 = &#8220;Flip&#8221;;<\/p>\n<p align=\"LEFT\">string str2 = &#8220;Flop&#8221;;<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;Before: {0}, {1} &#8220;, str1, str2);<\/p>\n<p align=\"LEFT\">SwapStrings(ref str1, ref str2);<\/p>\n<p align=\"LEFT\">Console.WriteLine(&#8220;After: {0}, {1} &#8220;, str1, str2);<\/p>\n<p align=\"LEFT\">Console.ReadLine();<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">&gt;&gt;output parameter do not need to initialize before the passed to the method.it\u00a0must assign when before \u00a0exiting the method calling. &gt;&gt;reference parameter must assign the before passed to the method. The reason is that passing the reference to an existing variable. If not assign works as unassigned variable. \/\/ Returning multiple output parameters. static void FillTheseValues(out int a, out string&hellip; <a href=\"http:\/\/mairwa.com\/wordpress\/?p=42\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7,11],"tags":[],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-c-vb","category-c","category-oop","xfolkentry"],"_links":{"self":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42"}],"version-history":[{"count":0,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions"}],"wp:attachment":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}