﻿
{"id":293,"date":"2012-03-21T00:48:36","date_gmt":"2012-03-21T00:48:36","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=293"},"modified":"2012-05-28T12:58:43","modified_gmt":"2012-05-28T12:58:43","slug":"cta-generic-class-tanimlama","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-generic-class-tanimlama\/","title":{"rendered":"C# Generic Class Tan\u0131mlama"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Bu yaz\u0131mda C#&#8217;ta Generic Class tan\u0131mlamay\u0131 g\u00f6sterece\u011fim.Generic s\u0131n\u0131flar temel olarak normal s\u0131n\u0131flar ile ayn\u0131 \u00f6zellikleri g\u00f6stermektedir.Generic s\u0131n\u0131flar\u0131n normal s\u0131n\u0131flardan fark\u0131,kullan\u0131lacak olan tiplerin s\u0131n\u0131f tan\u0131mlama a\u015famas\u0131nda belirtilmesidir.<br \/>\n<!--more--><br \/>\nBasit bir Generic s\u0131n\u0131f\u0131 a\u015fa\u011f\u0131daki gibidir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class ListGeneric\r\n    {\r\n\r\n    }\r\n<\/pre>\n<p><em>Not : Generic s\u0131n\u0131flarda overload(a\u015f\u0131r\u0131 y\u00fckleme) i\u015flemi m\u00fcmk\u00fcn de\u011fildir.<\/em><\/p>\n<p>Yukar\u0131daki tan\u0131mlad\u0131\u011f\u0131m Generic s\u0131n\u0131f\u0131m\u0131z\u0131n nesnesini olu\u015ftururken ifadesindeki &#8220;T&#8221; yerine benden bir tip isteyecektir.\u00d6rn;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nListGeneric koleksiyon = new ListGeneric();\r\n<\/pre>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi kendim Generic bir s\u0131n\u0131f tan\u0131mlam\u0131\u015f oldum.<br \/>\nifadesindeki,&#8221;T&#8221; &#8220;Type(tip)&#8221; kelimesindeki ba\u015f harfi temsil etmektedir.Yani bir tip istemektedir.Bu parametreye herhangi bir veri t\u00fcr\u00fcnden parametre girebiliriz.<\/p>\n<hr \/>\n<p>\u015eimdi a\u015fa\u011f\u0131daki kodlar\u0131 inceleyiniz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class ListGeneric\r\n    {\r\n        T ad;\r\n        public T Ad\r\n        {\r\n            get\r\n            {\r\n                return ad;\r\n            }\r\n            set\r\n            {\r\n                ad = value;\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<p>Yukar\u0131daki yap\u0131y\u0131 a\u00e7\u0131klayay\u0131m.&lt;T&gt; parametresinde &#8220;T&#8221; de\u011feri bir veri tipini temsil etmektedir.Bir tip oldu\u011fundan dolay\u0131 &#8220;T ad&#8221; koduyla bir de\u011fi\u015fken tan\u0131mlanm\u0131\u015ft\u0131r.Yani &#8220;T&#8221; tipinden, &#8220;ad&#8221; isminde bir de\u011fi\u015fken.(T tipi bu Generic s\u0131n\u0131f\u0131ndan nesne olu\u015fturulurken yukar\u0131da g\u00f6sterdi\u011fim \u015fekilde verilmi\u015f olacakt\u0131r.)Bu &#8220;ad&#8221; ismindeki fielda(de\u011fi\u015fken) &#8220;Ad&#8221; isminde geriye &#8220;T&#8221; tipinde d\u00f6nen bir property tan\u0131mlanm\u0131\u015ft\u0131r.Bu propertynin set blo\u011fu sayesinde, &#8220;ad&#8221; field\u0131na d\u0131sardan &#8220;T&#8221; tipinde veri girilebilecek ve get blo\u011fu sayesinde, &#8220;ad&#8221; field\u0131 okunabilecektir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            ListGeneric koleksiyon = new List();\r\n            koleksiyon.Ad = &quot;Gen\u00e7ay&quot;;\r\n            ListGeneric koleksiyon2 = new List();\r\n            koleksiyon2.Ad = 12;\r\n<\/pre>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi Generic s\u0131n\u0131f\u0131m\u0131zdan olu\u015fturdu\u011fumuz nesnelerde &lt;&gt; operat\u00f6rleri aras\u0131nda verdi\u011fimiz veri t\u00fcr\u00fcne g\u00f6re &#8220;Ad&#8221; propertysi \u00e7al\u0131\u015fmaktad\u0131r.<\/p>\n<hr \/>\n<p><strong>Generic S\u0131n\u0131flarda T\u00fcreme<\/strong><br \/>\nGeneric s\u0131n\u0131flar kal\u0131t\u0131m al\u0131p,kal\u0131t\u0131m verebilirler.Burada dikkat etmemiz konu, Generic s\u0131n\u0131f\u0131n kal\u0131t\u0131m ald\u0131\u011f\u0131 s\u0131n\u0131f ismi ile, Gneric s\u0131n\u0131f\u0131n\u0131n &lt;&gt; operat\u00f6rleri aras\u0131ndaki isim ayn\u0131 olamaz.\u00d6rn;<em>GenerikOrnekS\u0131n\u0131f:H{}<\/em>.E\u011fer bu \u015fekilde bir kullan\u0131m yaparsan\u0131z hata ile kar\u015f\u0131la\u015facaks\u0131n\u0131z.<br \/>\nBir sonraki yaz\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>Bu yaz\u0131mda C#&#8217;ta Generic Class tan\u0131mlamay\u0131 g\u00f6sterece\u011fim.Generic s\u0131n\u0131flar temel olarak normal s\u0131n\u0131flar ile ayn\u0131 \u00f6zellikleri g\u00f6stermektedir.Generic s\u0131n\u0131flar\u0131n normal s\u0131n\u0131flardan fark\u0131,kullan\u0131lacak olan tiplerin s\u0131n\u0131f tan\u0131mlama a\u015famas\u0131nda belirtilmesidir.<!-- 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":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[145,175],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-c-sharp-c","tag-generic","tag-generic-class"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/293","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=293"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}