﻿
{"id":4161,"date":"2016-04-24T14:52:36","date_gmt":"2016-04-24T14:52:36","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=4161"},"modified":"2016-04-24T14:52:36","modified_gmt":"2016-04-24T14:52:36","slug":"c-6-0-string-interpolation","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-6-0-string-interpolation\/","title":{"rendered":"C# 6.0 String Interpolation"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>C# 6.0 versiyonuyla gelen lakin \u00e7oktan ge\u00e7 kal\u0131nm\u0131\u015f bir \u00f6zellik olan String Interpolation&#8217;dan bahsedece\u011fim. String ifadelerde de\u011fi\u015fken de\u011ferlerini ifadeye entegre edebilmek i\u00e7in string.Format komutunu a\u015fa\u011f\u0131daki gibi kullan\u0131yorduk.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            string Ad = &quot;Gen\u00e7ay&quot;;\r\n            string SoyAd = &quot;Y\u0131ld\u0131z&quot;;\r\n            int Yas = 24;\r\n\r\n            string Mesaj = string.Format(&quot;Ad\u0131 : {0}, Soyad\u0131 : {1} olan ki\u015fi {2} ya\u015f\u0131nda.&quot;, Ad, SoyAd, Yas);\r\n<\/pre>\n<p>Bu kullan\u0131mda de\u011fi\u015fken say\u0131s\u0131n\u0131 onlarca fazlala\u015ft\u0131r\u0131rsak e\u011fer \u00e7\u0131kabilecek kar\u0131\u015f\u0131kl\u0131\u011f\u0131 art\u0131k siz d\u00fc\u015f\u00fcn\u00fcn. Kullanmayan bilemez. Yeni bir de\u011feri entegre etmek istedi\u011fimizde ya s\u00fcsl\u00fc parantezler i\u00e7erisindeki say\u0131sal de\u011ferler kar\u0131\u015f\u0131r, ya s\u0131ralar\u0131 kar\u0131\u015f\u0131r ya da g\u00f6zden ka\u00e7\u0131r\u0131p 3&#8217;ten 5&#8217;e transit ge\u00e7i\u015f yapard\u0131k. Bunlar\u0131n yan\u0131nda onlarca de\u011fi\u015fkenden hangisi nereye denk geliyordu kestirebilmek i\u00e7in amele\u00fcs y\u00f6ntemiyle dakikalar\u0131m\u0131 harcad\u0131\u011f\u0131m\u0131 bilirim.<\/p>\n<p>\u0130\u015fte yeni versiyonda gelen String Interpolation \u00f6zelli\u011fi sayesinde hardcoded tarzda yaz\u0131mdan kurtuluyor, a\u015fa\u011f\u0131daki prototipte yukar\u0131daki \u00f6rneklendirmeyi ger\u00e7ekle\u015ftirebiliyoruz.<\/p>\n<p style=\"text-align: center;\"><span style=\"color: #808080;\"><em><strong>string Metin = <span style=\"color: #ff0000;\">$<\/span>&#8220;metin <span style=\"color: #800080;\">{de\u011fi\u015fken}<\/span> metin <span style=\"color: #800080;\">{de\u011fi\u015fken2}<\/span> metin <span style=\"color: #800080;\">{de\u011fi\u015fken3}<\/span>&#8230;&#8221;;<\/strong><\/em><\/span><\/p>\n<p style=\"text-align: center;\">\n<p>String ifade ba\u015f\u0131na <strong>$<\/strong> i\u015fareti koyarsan\u0131z e\u011fer String Interpolation \u00f6zelli\u011fi o metin i\u00e7in Compiler taraf\u0131ndan etkinle\u015ftiriliyor ve yazd\u0131\u011f\u0131m\u0131z s\u00fcsl\u00fc parantezler{} de IDE bize Intellisense ile e\u015flik ediyor.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            string Ad = &quot;Gen\u00e7ay&quot;;\r\n            string SoyAd = &quot;Y\u0131ld\u0131z&quot;;\r\n            int Yas = 24;\r\n\r\n            string Mesaj = $&quot;Ad\u0131 : {Ad}, Soyad\u0131 : {SoyAd} olan ki\u015fi {Yas} ya\u015f\u0131nda.&quot;;\r\n<\/pre>\n<p>Bunlar\u0131n yan\u0131nda string.Format&#8217;ta oldu\u011fu gibi \u00e7e\u015fitli formatlar\u0131da String Interpolation i\u00e7erisinde a\u015fa\u011f\u0131daki \u00f6rnek misali kullanabilmekteyiz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            double Deger = 6.021023;\r\n            string Metin = $&quot;De\u011fer = {Deger:00.00}&quot;;\r\n<\/pre>\n<p>String Interpolation \u00f6zeli\u011fi, derleme zaman\u0131 \u00e7al\u0131\u015fan ve arka planda string.Format kal\u0131b\u0131n\u0131 olu\u015fturan bir \u00f6zelli\u011fe sahiptir.<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<\/p>\n<p>\u015eimdilik ho\u015f\u00e7akal\u0131n.<\/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>C# 6.0 versiyonuyla gelen lakin \u00e7oktan ge\u00e7 kal\u0131nm\u0131\u015f bir \u00f6zellik olan String Interpolation&#8217;dan bahsedece\u011fim. String ifadelerde de\u011fi\u015fken de\u011ferlerini ifadeye entegre edebilmek i\u00e7in string.Format komutunu a\u015fa\u011f\u0131daki gibi kullan\u0131yorduk. string Ad = &quot;Gen\u00e7ay&quot;; string SoyAd =&#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":3223,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[720],"tags":[897,685,1136,1137,1135,1138],"class_list":["post-4161","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-6-0","tag-operatoru","tag-685","tag-hardcoded","tag-intellisense","tag-string-interpolation","tag-string-format"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4161","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=4161"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4161\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3223"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=4161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=4161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=4161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}