﻿
{"id":19709,"date":"2020-12-05T23:36:59","date_gmt":"2020-12-05T23:36:59","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=19709"},"modified":"2020-12-05T23:36:59","modified_gmt":"2020-12-05T23:36:59","slug":"c-9-0-pattern-matching-enhancements","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-9-0-pattern-matching-enhancements\/","title":{"rendered":"C# 9.0 &#8211; Pattern Matching Enhancements"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Pattern Matching&#8217;ler ilk olarak C# 6.0&#8217;da tan\u0131t\u0131ld\u0131lar ve ard\u0131ndan C# 7.0&#8217;da<span style=\"font-size:10px;\">(bknz : <a href=\"https:\/\/www.gencayyildiz.com\/blog\/c-7-0-pattern-matching\/\" rel=\"noopener noreferrer\" target=\"_blank\">C# 7.0 \u2013 Pattern Matching<\/a>)<\/span> daha da geli\u015ftirildiler ve C# 8.0&#8217;da<span style=\"font-size:10px;\">(bknz : <a href=\"https:\/\/www.gencayyildiz.com\/blog\/c-8-0-switch-expressionproperty-tuple-positional-patterns\/\" rel=\"noopener noreferrer\" target=\"_blank\">C# 8.0 \u2013 Switch Expression(Property \u2013 Tuple \u2013 Positional Patterns)<\/a>)<\/span> ise \u00fczerine daha da ilgin\u00e7 \u00f6zellikler eklediler ve son olarak C# 9.0&#8217;da harika hale getirdiler \ud83d\ude42<\/p>\n<p>Bu i\u00e7eri\u011fimizde; <em>Simple Type Patterns<\/em>, <em>Relational Patterns<\/em>, <em>Logical Patterns<\/em> ve <em>Not Patterns<\/em> olmak \u00fczere d\u00f6rt desen olarak gelen C# 9.0 Pattern Matching yeniliklerini inceliyor olaca\u011f\u0131z.<\/p>\n<p>Gelin bu desenleri s\u0131ras\u0131yla tek tek ele alal\u0131m;<\/p>\n<h3 style=\"color:#e83e8c;\">Simple Type Patterns<\/h3>\n<p>Bir de\u011fi\u015fkenin belirli bir t\u00fcrde olup olmad\u0131\u011f\u0131n\u0131 h\u0131zl\u0131 bir \u015fekilde kontrol etmemizi sa\u011flayan desendir. C# 9.0&#8217;dan \u00f6nceki s\u00fcr\u00fcmlerde t\u00fcr kontrol\u00fc yap\u0131l\u0131rken t\u00fcr bildirimlerinin yan\u0131na de\u011fi\u015fken ad\u0131 tan\u0131mlamas\u0131 yahut <a href=\"https:\/\/www.gencayyildiz.com\/blog\/c-7-0-discard-kavrami\/\" rel=\"noopener noreferrer\" target=\"_blank\">Discard<\/a> ifadesinin kullan\u0131lmas\u0131 zaruriydi. C# 9.0 ile bu gereksiz zorunluluk ortadan kald\u0131r\u0131lm\u0131\u015f ve direkt olarak t\u00fcr kontrol i\u015flemine odaklan\u0131lmas\u0131 sa\u011flanm\u0131\u015ft\u0131r.<\/p>\n<table>\n<thead>\n<tr>\n<th>C# 9.0 \u00f6ncesi<\/th>\n<th>C# 9.0 sonras\u0131<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"219\" height=\"138\" class=\"aligncenter size-full wp-image-19718\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-1.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"217\" height=\"139\" class=\"aligncenter size-full wp-image-19719\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Bir ba\u015fka \u00f6rnek,<\/p>\n<table>\n<thead>\n<tr>\n<th>C# 9.0 \u00f6ncesi<\/th>\n<th>C# 9.0 sonras\u0131<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-2.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"349\" height=\"122\" class=\"aligncenter size-full wp-image-19724\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-2.jpg 349w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-2-300x105.jpg 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/a><\/td>\n<td><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-3.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"343\" height=\"118\" class=\"aligncenter size-full wp-image-19725\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-3.jpg 343w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-3-300x103.jpg 300w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 style=\"color:#e83e8c;\">Relational Patterns<\/h3>\n<p>Desenlerde <code><<\/code>, <code>><\/code>, <code><=<\/code> ve <code>>=<\/code> operat\u00f6rleri kullan\u0131labilmekte ve belirli kar\u015f\u0131la\u015ft\u0131rmalar h\u0131zl\u0131ca ger\u00e7ekle\u015ftirilebilmektedir. \u00d6rne\u011fin;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-6.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-6.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"247\" height=\"139\" class=\"aligncenter size-full wp-image-19736\" \/><\/a><br \/>\nYukar\u0131daki gibi t\u00fcm ihtimallerin de\u011ferlendirildi\u011fi kodlarda '_'(hi\u00e7biri) operat\u00f6r\u00fcne gerek kalmayaca\u011f\u0131 i\u00e7in kullan\u0131lmas\u0131na m\u00fcsaade etmeyecektir;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-7.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-7.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"247\" height=\"159\" class=\"aligncenter size-full wp-image-19738\" \/><\/a><br \/>\nLakin ihtimallerin hepsi de\u011ferlendirilmedi\u011fi taktirde '_'(hi\u00e7biri) operat\u00f6r\u00fc kullan\u0131labilmektedir.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-8.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-8.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"246\" height=\"139\" class=\"aligncenter size-full wp-image-19740\" \/><\/a><\/p>\n<h3 style=\"color:#e83e8c;\">Logical Patterns<\/h3>\n<p><code>and<\/code>, <code>or<\/code> ve <code>not<\/code> gibi mant\u0131ksal operat\u00f6rler kullan\u0131labilmektedir. Misal;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-4.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"367\" height=\"99\" class=\"aligncenter size-full wp-image-19730\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-4.jpg 367w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-4-300x81.jpg 300w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/a><br \/>\nyukar\u0131daki ekran g\u00f6r\u00fcnt\u00fcs\u00fcndeki \u00f6rne\u011fi incelerseniz e\u011fer ilgili product'\u0131n <code>Technologic or Computer<\/code> kodu sayesinde iki farkl\u0131 t\u00fcrden biri olma durumu de\u011ferlendirilmektedir. Burada bu t\u00fcrler \u00fczerinde gerekli kontrol sa\u011fland\u0131\u011f\u0131 i\u00e7in herhangi birinin ayn\u0131 switch blo\u011fu i\u00e7erisinde kontrol ama\u00e7l\u0131 tekrar kullan\u0131lmas\u0131na m\u00fcsaade edilmeyecektir.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-5.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"372\" height=\"123\" class=\"aligncenter size-full wp-image-19732\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-5.jpg 372w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-5-300x99.jpg 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><br \/>\nG\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere b\u00fct\u00fcnsel mant\u0131k i\u015flemekte ve 'Computer' t\u00fcr\u00fcn\u00fcn kontrol edilmesi l\u00fczumsuz olaca\u011f\u0131 i\u00e7in derleyici taraf\u0131ndan bu i\u015flem reddedilmektedir.<\/p>\n<p>\u0130lgili deseni yukar\u0131daki Relational Pattern ile \u00f6rneklendirirsek e\u011fer;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-9.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-9.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"627\" height=\"143\" class=\"aligncenter size-full wp-image-19745\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-9.jpg 627w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-9-300x68.jpg 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/a><br \/>\n\u00d6zellikle bu iki desenin olduk\u00e7a uyumlu oldu\u011fu kanaatindeyim \ud83d\ude42<\/p>\n<h3 style=\"color:#e83e8c;\">Not Patterns<\/h3>\n<p><code>not<\/code> operat\u00f6r\u00fcn\u00fcn kullan\u0131labildi\u011fi bir desendir. Yukar\u0131daki 'Logical Patterns'de en son 'Relational Pattern' ile verilen \u00f6rnekte oldu\u011fu gibi e\u015fit de\u011fillik durumunda kullan\u0131labildi\u011fi gibi <code>is not Type<\/code> tarz\u0131 kal\u0131psal keyword'lerde de kullan\u0131labilmektedir. Misal olarak;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-10.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-10.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"348\" height=\"119\" class=\"aligncenter size-full wp-image-19751\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-10.jpg 348w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-10-300x103.jpg 300w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/a><br \/>\nyukar\u0131daki \u00f6rne\u011fi incelerseniz, verilen product'\u0131n 'Technologic' ve 'Computer' olmamas\u0131 durumunda e\u011fer 'Goggles'da de\u011filse 'G\u00f6zl\u00fck' de\u011ferini d\u00f6nd\u00fcrecektir.<\/p>\n<p>Bir ba\u015fka \u00f6rnek vermemiz gerekirse e\u011fer;<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-11.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2020\/12\/C-9.0-Pattern-Matching-Enhancements-11.jpg\" alt=\"C# 9.0 - Pattern Matching Enhancements\" width=\"228\" height=\"97\" class=\"aligncenter size-full wp-image-19753\" \/><\/a><\/p>\n<p>Sonu\u00e7 olarak; C# 9.0'da, \u00f6nceki s\u00fcr\u00fcmlerde gelen g\u00fczel ve kullan\u0131\u015fl\u0131 \u00f6zelliklerin daha da nitelikli hale getirildi\u011fini ve semantik a\u00e7\u0131danda daha g\u00fc\u00e7lendirildi\u011fini g\u00f6zlemliyoruz.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle...<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere...<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar...<\/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, Pattern Matching&#8217;ler ilk olarak C# 6.0&#8217;da tan\u0131t\u0131ld\u0131lar ve ard\u0131ndan C# 7.0&#8217;da(bknz : C# 7.0 \u2013 Pattern Matching) daha da geli\u015ftirildiler ve C# 8.0&#8217;da(bknz : C# 8.0 \u2013 Switch Expression(Property \u2013 Tuple \u2013 Positional&#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":19209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,3928],"tags":[3929,3991,3990,3993,3994,1519,3989,3992,3995],"class_list":["post-19709","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","category-c-9-0","tag-c-9-0","tag-c-9-0-pattern-matching","tag-c-9-0-pattern-matching-enhancements","tag-logical-patterns","tag-not-patterns","tag-pattern-matching","tag-pattern-matching-enhancements","tag-relational-patterns","tag-simple-type-pattern"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/19709","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=19709"}],"version-history":[{"count":35,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/19709\/revisions"}],"predecessor-version":[{"id":19757,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/19709\/revisions\/19757"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/19209"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=19709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=19709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=19709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}