{"id":660,"date":"2016-12-07T17:07:06","date_gmt":"2016-12-07T17:07:06","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=223"},"modified":"2022-09-13T15:00:07","modified_gmt":"2022-09-13T14:00:07","slug":"reference-2","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/memory-uwp-programming-in-c\/pointers-memory-uwp-programming-in-c\/reference-2","title":{"rendered":"Reference"},"content":{"rendered":"<h4>\n\tPass A Reference To A Function, Method, etc<\/h4>\n<p>Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling environment.<\/p>\n<p>You just use the &#8216;ref&#8217; or &#8216;out&#8217;&nbsp;keyword:<\/p>\n<p style=\"margin-left: 40px\">\n\t&#8216;ref&#8217; tells the compiler that the object is initialized before entering the function<\/p>\n<p style=\"margin-left: 40px\">\n\t&#8216;out&#8217; tells the compiler that the object will be initialized inside the function<\/p>\n<p>\tSo &#8216;ref&#8217; is two-ways and &#8216;out&#8217; is out-only<\/p>\n<pre><code>\n\tpublic void MyMethodName(ref int[] BookIds, ref string[] BookLanguages)\n\t{\n\t\/\/or:\n\tpublic void MyMethodName(out int[] BookIds, out string[] BookLanguages)\n\t{\n<\/code><\/pre>\n<h4>\n\tCalling the method<\/h4>\n<p>You need to use the &#8216;ref&#8217; or &#8216;out&#8217; keyword here too<\/p>\n<pre><code>\n\tMyMethodName(ref TheBookIds, ref TheBookLanguages);\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pass A Reference To A Function, Method, etc Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling environment. You just use the &#8216;ref&#8217; or &#8216;out&#8217;&nbsp;keyword: &#8216;ref&#8217; tells the compiler that the object is initialized before entering the [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130],"tags":[],"class_list":["post-660","post","type-post","status-publish","format-standard","hentry","category-pointers-memory-uwp-programming-in-c"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=660"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/660\/revisions"}],"predecessor-version":[{"id":1169,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/660\/revisions\/1169"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}