﻿
{"id":6411,"date":"2017-05-24T22:51:55","date_gmt":"2017-05-24T22:51:55","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=6411"},"modified":"2017-05-24T22:51:55","modified_gmt":"2017-05-24T22:51:55","slug":"cta-gostericipointer-struct-turunden-gostericiler-ve-ok-operatoru-xi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-gostericipointer-struct-turunden-gostericiler-ve-ok-operatoru-xi\/","title":{"rendered":"C#\u2019ta G\u00f6sterici(Pointer) \u2013 struct T\u00fcr\u00fcnden G\u00f6stericiler ve &#8220;->&#8221;(Ok) Operat\u00f6r\u00fc \u2013 XI"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>\u015eu ana kadar g\u00f6stericiler \u00fczerine yazm\u0131\u015f oldu\u011fumuz yaz\u0131 dizisinde g\u00f6stericileri de\u011fer tipli de\u011fi\u015fkenler \u00fczerinde kulland\u0131\u011f\u0131m\u0131zdan bahsettik. Bunun yan\u0131 s\u0131ra enum ve struct t\u00fcrlerininde i\u015faret\u00e7iler e\u015fli\u011finde kullan\u0131labilir bir yap\u0131 arz etmekte olduklar\u0131na de\u011findik. Tabi ki de bu i\u00e7eri\u011fimizde bunun aksisini s\u00f6ylemeyece\u011fiz. Bilakis struct t\u00fcr\u00fcnden g\u00f6stericiler \u00fczerinde biraz daha detayland\u0131rmada bulunacak ve &#8220;->&#8221;(Ok) operat\u00f6r\u00fcn\u00fc irdeleyece\u011fiz.<\/p>\n<p>Biliyorsunuz ki &#8220;int&#8221;, &#8220;char&#8221;, &#8220;double&#8221;, &#8220;decimal&#8221;, &#8220;float&#8221; vs. gibi t\u00fcrler de\u011fer tipli t\u00fcrlerdir. Yani belle\u011fin stack k\u0131sm\u0131nda tutulmaktad\u0131rlar. Ayriyetten her bir de\u011fer t\u00fcr\u00fc aslen bir struct yani yap\u0131d\u0131r. Bu \u00f6nergenin terside do\u011frudur. Her bir struct aslen de\u011fer tipli bir de\u011fi\u015fkendir.<\/p>\n<p>Haliyle g\u00f6stericiler nas\u0131l de\u011fer tipli de\u011fi\u015fkenleri i\u015faretleyebiliyorsa, bu i\u015flem dolay\u0131s\u0131yla structlar i\u00e7inde ge\u00e7erlidir.<\/p>\n<p>Bir struct\u0131n, herhangi bir g\u00f6sterici taraf\u0131ndan i\u015faretlenmesini istiyorsak e\u011fer tek \u015fart o struct\u0131n \u00fcye elemanlar\u0131n\u0131n tamam\u0131n\u0131n de\u011fer tipli olmas\u0131 gerekmektedir.<\/p>\n<p>A\u015fa\u011f\u0131daki kod blo\u011funu incelerseniz e\u011fer;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static unsafe void Main(string&#x5B;] args)\r\n        {\r\n            MyStruct m = new MyStruct();\r\n            MyStruct* mpointer = &amp;m;\r\n\r\n            Console.Read();\r\n        }\r\n    }\r\n    struct MyStruct\r\n    {\r\n        public int a;\r\n        public bool b;\r\n        public char c;\r\n    }\r\n<\/pre>\n<p>&#8220;MyStruct&#8221; isimli struct\u0131n \u00fcye elemanlar\u0131n\u0131n hepsinin de\u011fer tipli olmas\u0131 ilgili yap\u0131y\u0131 pointerlar ile i\u015faretlemeyi sa\u011flamaktad\u0131r.<\/p>\n<p>Ayr\u0131ca burada dikkat etmenizi istedi\u011fim bir di\u011fer husus, struct\u0131n \u00fcye elemanlar\u0131 i\u00e7erisinde gene struct tipte elemanlar bulunabilir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static unsafe void Main(string&#x5B;] args)\r\n        {\r\n            MyStruct m = new MyStruct();\r\n            MyStruct* mpointer = &amp;m;\r\n            Console.WriteLine((*mpointer).myStruct.MyProperty2);\r\n            Console.Read();\r\n        }\r\n    }\r\n    struct MyStruct\r\n    {\r\n        public int a;\r\n        public bool b;\r\n        public char c;\r\n        public int MyProperty { get; set; }\r\n        public MyStruct2 myStruct { get; set; }\r\n    }\r\n    struct MyStruct2\r\n    {\r\n        public bool MyProperty2 { get; set; }\r\n    }\r\n<\/pre>\n<p>gibi&#8230;<\/p>\n<blockquote><p><strong><em>struct i\u00e7erisinde de\u011fer tipte olmayan \u00fcye elemanlar, managed type(y\u00f6netilen tip) olmas\u0131ndan dolay\u0131 g\u00f6stericiler taraf\u0131ndan i\u015faret edilememektedir. Bu y\u00fczden g\u00f6stericiler ile i\u015faretlerken struct i\u00e7erisinde de\u011fer tipin d\u0131\u015f\u0131nda ba\u015fka elemanlar\u0131n bulunmamas\u0131 gerekmektedir.<\/em><\/strong><\/p><\/blockquote>\n<h4>&#8220;->&#8221;(Ok) Operat\u00f6r\u00fc<\/h4>\n<p>struct t\u00fcr\u00fcnden g\u00f6stericilerin i\u015faretledi\u011fi bellek adresindeki de\u011fere &#8220;*&#8221;(y\u0131ld\u0131z) ve &#8220;.&#8221;(nokta) operat\u00f6rleri ile a\u015fa\u011f\u0131daki gibi kolayl\u0131kla eri\u015febilmekteyiz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 struct T\u00fcr\u00fcnden G\u00f6stericiler ve &quot;-&gt;&quot;(Ok) Operat\u00f6r\u00fc \u2013 XI\" width=\"513\" height=\"392\" class=\"aligncenter size-full wp-image-6422\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI.png 513w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI-300x229.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/a><\/p>\n<p>&#8220;->&#8221;(Ok) operat\u00f6r\u00fc ise benzer mant\u0131kla \u00e7al\u0131\u015fan, sadece struct g\u00f6stericilerine \u00f6zel olarak tasarlanm\u0131\u015f bir i\u015flevselli\u011fe sahiptir. struct g\u00f6stericisinin i\u015faretledi\u011fi yap\u0131n\u0131n bellek adresindeki nesneyi direkt olarak elde edip \u00fcye elemanlar\u0131n\u0131 bizlere getirmektedir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI-1.png\" alt=\"C#\u2019ta G\u00f6sterici(Pointer) \u2013 struct T\u00fcr\u00fcnden G\u00f6stericiler ve &quot;-&gt;&quot;(Ok) Operat\u00f6r\u00fc \u2013 XI\" width=\"495\" height=\"391\" class=\"aligncenter size-full wp-image-6424\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI-1.png 495w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2017\/05\/C\u2019ta-G\u00f6stericiPointer-\u2013-struct-T\u00fcr\u00fcnden-G\u00f6stericiler-ve-Ok-Operat\u00f6r\u00fc-\u2013-XI-1-300x237.png 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><\/p>\n<blockquote><p><em>&#8220;->&#8221; operat\u00f6r\u00fcyle struct\u0131n elemanlar\u0131na ula\u015f\u0131rken elemanlar\u0131n eri\u015fim belirleyicilerinin public olmas\u0131na \u00f6zen g\u00f6steriniz.<\/em><\/p><\/blockquote>\n<p>Bu i\u00e7eri\u011fimizle de g\u00f6stericiler dizisi \u00fczerine son makalemizi kaleme alm\u0131\u015f olduk.<br \/>\nHay\u0131rl\u0131 u\u011furlu olsun.<\/p>\n<p>Umar\u0131m bu yaz\u0131 dizisinde sizlere yard\u0131mc\u0131 olabilmi\u015f ve niyetimi tam bir \u015fekilde sa\u011f sa\u011flim yerine getirebilmi\u015fimdir.<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, \u015eu ana kadar g\u00f6stericiler \u00fczerine yazm\u0131\u015f oldu\u011fumuz yaz\u0131 dizisinde g\u00f6stericileri de\u011fer tipli de\u011fi\u015fkenler \u00fczerinde kulland\u0131\u011f\u0131m\u0131zdan bahsettik. Bunun yan\u0131 s\u0131ra enum ve struct t\u00fcrlerininde i\u015faret\u00e7iler e\u015fli\u011finde kullan\u0131labilir bir yap\u0131 arz etmekte olduklar\u0131na de\u011findik. Tabi&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[897,1758,1813,1814,1761,1812,1801,1811,1748,1810],"class_list":["post-6411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","tag-operatoru","tag-c-operatoru","tag-c-ok-operatoru","tag-c-struct-turunden-gostericiler","tag-cta-gosterici","tag-cta-gostericiler","tag-cta-pointerlar","tag-ok-operatoru","tag-pointer","tag-struct-turunden-gostericiler"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=6411"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/6411\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=6411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=6411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=6411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}