﻿
{"id":3781,"date":"2016-03-26T16:31:28","date_gmt":"2016-03-26T16:31:28","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=3781"},"modified":"2016-03-26T16:32:34","modified_gmt":"2016-03-26T16:32:34","slug":"cta-iequatable-interfacei-ile-nesne-karsilastirma","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/cta-iequatable-interfacei-ile-nesne-karsilastirma\/","title":{"rendered":"C#&#8217;ta IEquatable Interface&#8217;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Elimizde T tipinden bir Entity bulunsun ve bu entityden birer koleksiyon ve nesne oldu\u011funu varsayal\u0131m. Ben genellikle elimdeki nesnenin, koleksiyonun Contains metodu arac\u0131l\u0131\u011f\u0131yla varl\u0131\u011f\u0131 ya da yoklu\u011fu hakk\u0131nda net bilgi alamad\u0131m. \u0130\u015fte b\u00f6yle bir durumda IEquatable Interface&#8217;i ile kar\u015f\u0131la\u015ft\u0131m.<\/p>\n<p>IEquatable Interface&#8217;i, miras\u0131 s\u0131n\u0131fa Equals metodunu uygulatan ve bu metod arac\u0131l\u0131\u011f\u0131yla nesne kar\u015f\u0131la\u015ft\u0131rmam\u0131z\u0131 yapt\u0131ran bir yap\u0131d\u0131r.<\/p>\n<p>\u00d6rnek olarak a\u015fa\u011f\u0131daki yap\u0131y\u0131 Entityi ele alal\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Nesne\r\n    {\r\n        public int A { get; set; }\r\n        public string B { get; set; }\r\n        public bool C { get; set; }\r\n    }\r\n<\/pre>\n<p>\u015eimdi bu s\u0131n\u0131f\u0131m\u0131za IEquatable Interface&#8217;ini uygulayal\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Nesne: IEquatable&lt;Nesne&gt;\r\n    {\r\n        public int A { get; set; }\r\n        public string B { get; set; }\r\n        public bool C { get; set; }\r\n\r\n        public bool Equals(Nesne other)\r\n        {\r\n            return\r\n                this.A == other.A &amp;&amp;\r\n                this.B == other.B &amp;&amp;\r\n                this.C == other.C;\r\n        }\r\n    }\r\n<\/pre>\n<p>Yukar\u0131daki kod blo\u011funu incelerseniz e\u011fer &#8220;Nesne&#8221; tipimizde Equals metodu sayesinde verisel bir kar\u015f\u0131la\u015ft\u0131rma ger\u00e7ekle\u015ftirebiliyoruz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Nesne nesne1 = new Nesne { A = 1, B = &quot;1&quot;, C = true };\r\n            Nesne nesne2 = new Nesne { A = 1, B = &quot;1&quot;, C = true };\r\n            Console.WriteLine(nesne1.Equals(nesne2));\r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<div id=\"attachment_3782\" style=\"width: 136px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-iequatable-interfacei-ile-nesne-karsilastirma\/cta-iequatable-interfacei-ile-nesne-karsilastirma\/\" rel=\"attachment wp-att-3782\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3782\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/03\/Cta-IEquatable-Interfacei-\u0130le-Nesne-Kar\u015f\u0131la\u015ft\u0131rma.png\" alt=\"C#&#039;ta IEquatable Interface&#039;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma\" width=\"126\" height=\"64\" class=\"size-full wp-image-3782\" \/><\/a><p id=\"caption-attachment-3782\" class=\"wp-caption-text\">C#&#8217;ta IEquatable Interface&#8217;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma<\/p><\/div>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi nesneleri property de\u011ferlerine g\u00f6re kar\u015f\u0131la\u015ft\u0131rmaktad\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Nesne nesne1 = new Nesne { A = 1, B = &quot;1&quot;, C = true };\r\n            Nesne nesne2 = new Nesne { A = 2, B = &quot;2&quot;, C = false };\r\n            Console.WriteLine(nesne1.Equals(nesne2));\r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<div id=\"attachment_3783\" style=\"width: 129px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-iequatable-interfacei-ile-nesne-karsilastirma\/cta-iequatable-interfacei-ile-nesne-karsilastirma-2\/\" rel=\"attachment wp-att-3783\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3783\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/03\/Cta-IEquatable-Interfacei-\u0130le-Nesne-Kar\u015f\u0131la\u015ft\u0131rma-1.png\" alt=\"C#&#039;ta IEquatable Interface&#039;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma\" width=\"119\" height=\"63\" class=\"size-full wp-image-3783\" \/><\/a><p id=\"caption-attachment-3783\" class=\"wp-caption-text\">C#&#8217;ta IEquatable Interface&#8217;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma<\/p><\/div>\n<p>Peki Nesne Tipinden Bir Koleksiyonda Kar\u015f\u0131la\u015ft\u0131rmay\u0131 Nas\u0131l Yapaca\u011f\u0131z? diye sorarsan\u0131z e\u011fer a\u015fa\u011f\u0131daki kod blo\u011funu inceleyiniz.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            List&lt;Nesne&gt; Nesneler = new List&lt;Nesne&gt; {\r\n                 new Nesne { A = 1, B = &quot;1&quot;, C = true },\r\n                 new Nesne { A = 2, B = &quot;2&quot;, C = false },\r\n                 new Nesne { A = 3, B = &quot;3&quot;, C = true },\r\n                 new Nesne { A = 4, B = &quot;4&quot;, C = false },\r\n                 new Nesne { A = 5, B = &quot;5&quot;, C = true },\r\n                 new Nesne { A = 6, B = &quot;6&quot;, C = false }\r\n            };\r\n            Nesne nesne = new Nesne { A = 4, B = &quot;4&quot;, C = false };\r\n            var _Nesne = Nesneler.FirstOrDefault(n =&gt; n.Equals(nesne));\r\n            Console.WriteLine(_Nesne.A + &quot; &quot; + _Nesne.B + &quot; &quot; + _Nesne.C);\r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<div id=\"attachment_3785\" style=\"width: 137px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.gencayyildiz.com\/blog\/cta-iequatable-interfacei-ile-nesne-karsilastirma\/cta-iequatable-interfacei-ile-nesne-karsilastirma-3\/\" rel=\"attachment wp-att-3785\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3785\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/03\/Cta-IEquatable-Interfacei-\u0130le-Nesne-Kar\u015f\u0131la\u015ft\u0131rma-2.png\" alt=\"C#&#039;ta IEquatable Interface&#039;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma\" width=\"127\" height=\"65\" class=\"size-full wp-image-3785\" \/><\/a><p id=\"caption-attachment-3785\" class=\"wp-caption-text\">C#&#8217;ta IEquatable Interface&#8217;i \u0130le Nesne Kar\u015f\u0131la\u015ft\u0131rma<\/p><\/div>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi IEquatable Interface&#8217;i bu \u015fekilde bir kullan\u0131m kolayl\u0131\u011f\u0131 sa\u011flamaktad\u0131r. Eee akl\u0131n\u0131zun k\u00f6\u015fesinde bulunsun, laz\u0131m olursa bi el atars\u0131n\u0131z&#8230; \ud83d\ude42 <\/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, Elimizde T tipinden bir Entity bulunsun ve bu entityden birer koleksiyon ve nesne oldu\u011funu varsayal\u0131m. Ben genellikle elimdeki nesnenin, koleksiyonun Contains metodu arac\u0131l\u0131\u011f\u0131yla varl\u0131\u011f\u0131 ya da yoklu\u011fu hakk\u0131nda net bilgi alamad\u0131m. \u0130\u015fte b\u00f6yle&#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":[12,338,720],"tags":[988,987,986,168],"class_list":["post-3781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","category-c-5-0","category-c-6-0","tag-c-nesneleri-karsilastirma","tag-contains","tag-iequatable","tag-interface"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/3781","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=3781"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/3781\/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=3781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=3781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=3781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}