﻿
{"id":289,"date":"2012-03-21T00:45:31","date_gmt":"2012-03-21T00:45:31","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=289"},"modified":"2012-05-28T12:58:53","modified_gmt":"2012-05-28T12:58:53","slug":"cta-ozellestirilmis-koleksiyonlar-system-collections-specialized","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-ozellestirilmis-koleksiyonlar-system-collections-specialized\/","title":{"rendered":"C# \u00d6zelle\u015ftirilmi\u015f Koleksiyonlar &#8211; System.Collections.Specialized"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Bu yaz\u0131mda C#&#8217;ta \u00f6zelle\u015ftirilmi\u015f koleksiyonlar\u0131 inceleyece\u011fiz.\u00d6zelle\u015ftirilmi\u015f koleksiyonlar System.Collections.Specialized namespace i alt\u0131nda bulunurlar.ListDictionary,HybridDictionary,Queue ve Stack koleksiyonlar\u0131 mevcuttur.\u015eimdi gelin bu koleksiyon s\u0131n\u0131flar\u0131n\u0131 g\u00f6relim.<br \/>\n<!--more--><br \/>\n<strong>ListDictionary<\/strong><br \/>\nK\u00fc\u00e7\u00fck \u00f6l\u00e7ekli koleksiyon yap\u0131s\u0131 kurmak isteniyorsa bu koleksiyon yap\u0131s\u0131 tercih edilebilir.E\u011fer koleksiyon yap\u0131s\u0131n\u0131n key &#8211; value pairlerinden olu\u015fmas\u0131n\u0131 istiyorsak Hashtable ya da ListDictionary kullanabiliriz.Ama k\u00fc\u00e7\u00fck \u00f6l\u00e7ekli bir yap\u0131 ise ListDictionary tercih edilir.\u00c7\u00fcnk\u00fc daha h\u0131zl\u0131 \u00e7al\u0131\u015f\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            ListDictionary listD = new ListDictionary();\r\n            listD.Add(&quot;Ad\u0131&quot;, &quot;Gen\u00e7ay&quot;);\r\n            listD.Add(&quot;Soyad\u0131&quot;,&quot;Y\u0131ld\u0131z&quot;);\r\n            listD.Add(&quot;Meslegi&quot;,&quot;Yaz\u0131l\u0131m Uzman\u0131&quot;);\r\n<\/pre>\n<p>ListDictionary koleksiyonunu foreach d\u00f6ng\u00fcs\u00fcnde d\u00f6nmek istiyorsak e\u011fer,koleksiyondaki elemanlar\u0131 DictionaryEntry almam\u0131z gerekiyor.(DictionaryEntry &#8211; System.Collections namespaceindedir.)DictionaryEntry sayesinde Key ve Value propertylerine ula\u015fabiliyoruz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            foreach (DictionaryEntry item in listD)\r\n            {\r\n                MessageBox.Show(item.Key + &quot;:&quot; + item.Value);\r\n            }\r\n<\/pre>\n<p>ListDictionary koleksiyonun Sort diye bir metodu yoktur.Fakat constructor\u0131nda IComparer alan constructor mevcuttur.Ve bu constructor\u0131 kullanarak default s\u0131ralama kural\u0131 belirlenebilir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            CaseInsensitiveComparer sirala = new CaseInsensitiveComparer();\r\n            ListDictionary listD = new ListDictionary(sirala);\r\n<\/pre>\n<p><!--nextpage--><br \/>\n<strong>HybridDictionary<\/strong><br \/>\nHybridDictionary, ilk \u00f6nce i\u015fe ListDictionary olarak ba\u015flar.Koleksiyon yap\u0131s\u0131 b\u00fcy\u00fcd\u00fc\u011f\u00fc zaman Hashtable olarak \u00e7al\u0131\u015fmaya devam eder.<br \/>\n<!--nextpage--><br \/>\n<strong>Queue<\/strong><br \/>\nQueue koleksiyon yap\u0131s\u0131 FIFO(Firs In Firs Out &#8211; \u0130lk Giren \u0130lk \u00c7\u0131kar) mant\u0131\u011f\u0131na g\u00f6re \u00e7al\u0131\u015fan bir koleksiyon yap\u0131s\u0131d\u0131r.<br \/>\nBu koleksiyona eleman Enqueue() metodu ile eklenir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            Queue listQ = new Queue();\r\n            listQ.Enqueue(&quot;A&quot;);\r\n            listQ.Enqueue(&quot;B&quot;);\r\n            listQ.Enqueue(&quot;C&quot;);\r\n            listQ.Enqueue(1);\r\n            listQ.Enqueue(2);\r\n<\/pre>\n<p>Koleksiyondan eleman \u00e7\u0131kartmak i\u00e7in Dequeue() metodu kullan\u0131l\u0131r.Dequeue() metodu kald\u0131raca\u011f\u0131 eleman\u0131,geri g\u00f6nderir.Yani hem kald\u0131r\u0131r, hem de kald\u0131rd\u0131\u011f\u0131n\u0131 bize g\u00f6nderir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            Queue listQ = new Queue();\r\n            listQ.Enqueue(&quot;A&quot;);\r\n            listQ.Enqueue(&quot;B&quot;);\r\n            listQ.Enqueue(&quot;C&quot;);\r\n            listQ.Enqueue(1);\r\n            listQ.Enqueue(2);\r\n            foreach (object item in listQ)\r\n            {\r\n                MessageBox.Show(item.ToString());\r\n            }\r\n\/\/Buraya kadar s\u0131ras\u0131yla A,B,C,1 ve 2 olarak mesaj kutusunda elemanlar g\u00f6z\u00fckecektir.\r\n            listQ.Dequeue();\r\n            foreach (object item in listQ)\r\n            {\r\n                MessageBox.Show(item.ToString());\r\n            }\r\n\/\/Burda ise Dequeue() metodu \u00e7al\u0131\u015ft\u0131ktan sonra B,C,1 ve 2 olarak mesaj kutusunda elemanlar g\u00f6z\u00fckecektir.\r\n<\/pre>\n<p>Peek() metodu, koleksiyonun ilk giren eleman\u0131n\u0131 geri d\u00f6ner.Bu eleman\u0131 koleksiyondan \u00e7\u0131kartmaz.Dolay\u0131s\u0131yla Peek metodu ile sadece ilk giren elemana ula\u015f\u0131labilir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            MessageBox.Show(listQ.Peek().ToString());\r\n<\/pre>\n<p><!--nextpage--><strong>Stack<\/strong><br \/>\nStack koleksiyonu LIFO (Last In First Out &#8211; Son Giren \u0130lk \u00c7\u0131kar) mant\u0131\u011f\u0131na g\u00f6re \u00e7al\u0131\u015f\u0131r.<br \/>\nPush() metodu ile eleman eklenir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            Stack listS = new Stack();\r\n            listS.Push(&quot;A&quot;);\r\n            listS.Push(&quot;B&quot;);\r\n            listS.Push(&quot;C&quot;);\r\n            listS.Push(1);\r\n            listS.Push(2);\r\n<\/pre>\n<p>Pop() metodu ile en \u00fcstteki eleman(son eklenen) geri d\u00f6ner ve koleksiyondan \u00e7\u0131kar\u0131l\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n            Stack listS = new Stack();\r\n            listS.Push(&quot;A&quot;);\r\n            listS.Push(&quot;B&quot;);\r\n            listS.Push(&quot;C&quot;);\r\n            listS.Push(1);\r\n            listS.Push(2);\r\n            while (listS.Count &gt;0)\r\n            {\r\n                MessageBox.Show(listS.Pop() + &quot;-&quot; + listS.Count);\r\n            }\r\n<\/pre>\n<p>Yukar\u0131daki kodlar\u0131 \u00e7al\u0131\u015ft\u0131r\u0131rsak e\u011fer, son giren eleman &#8220;2&#8221; Pop() metodu taraf\u0131ndan silinecek.Tabi Pop() metodu silerken geri &#8220;2&#8221; eleman\u0131n\u0131 g\u00f6nderecektir.Normalde 5 elemanl\u0131 olan koleksiyonumuz 4 elemana d\u00fc\u015fecektir ve ilk mesaj kutusunda &#8220;2-4&#8221; mesaj\u0131n\u0131 g\u00f6rece\u011fiz.Sonrakilerde &#8220;1-3&#8243;,&#8221;C-2&#8243;,&#8221;B-1&#8221; ve &#8220;A-0&#8221; mesajlar\u0131n\u0131 g\u00f6rece\u011fiz.<\/p>\n<p>\u015eimdilik bu kadar.<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 \u00f6zelle\u015ftirilmi\u015f koleksiyonlar\u0131 inceleyece\u011fiz.\u00d6zelle\u015ftirilmi\u015f koleksiyonlar System.Collections.Specialized namespace i alt\u0131nda bulunurlar.ListDictionary,HybridDictionary,Queue ve Stack koleksiyonlar\u0131 mevcuttur.\u015eimdi gelin bu koleksiyon s\u0131n\u0131flar\u0131n\u0131 g\u00f6relim.<!-- 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":[174],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-c-sharp-c","tag-system-collections-specialized"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/289","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=289"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}