{"id":58991,"date":"2021-11-09T07:00:52","date_gmt":"2021-11-09T06:00:52","guid":{"rendered":"https:\/\/code-maze.com\/?p=58991"},"modified":"2021-12-21T12:46:34","modified_gmt":"2021-12-21T11:46:34","slug":"delegates-charp","status":"publish","type":"post","link":"https:\/\/code-maze.com\/delegates-charp\/","title":{"rendered":"C# Delegates"},"content":{"rendered":"<p>In this article, we&#8217;re going to talk about C# delegates, which are a prerequisite for learning events-based programming. Delegates are one of the fundamental building blocks of flexible applications, as they can be found in the vast majority of .NET framework code base and client libraries.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-advanced-topics\/DelegatesInCsharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<h2><a id=\"whatisdelegate\"><\/a>What is a C# Delegate?<\/h2>\n<p><strong>A C# delegate is a reference to a method.<\/strong> If we call a delegate, the referenced method is called instead. Delegates have all the necessary information to call a method with a specific signature and return type. We can pass delegates as an argument to other methods or we can store it in a structure or a class. <strong>We use delegates when we don&#8217;t know which method is going to be called at design time but only during runtime.<\/strong><\/p>\n<p>Delegates are widely used to implement <a href=\"https:\/\/code-maze.com\/csharp-events\/\" target=\"_blank\" rel=\"noopener\">events<\/a> and callback methods.<\/p>\n<h2><a id=\"declaringdelegates\"><\/a>Declaring Delegates<\/h2>\n<p>To declare a delegate we use the <code>delegate<\/code> keyword:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">delegate void PrintMessage(string text);<\/code><\/p>\n<p>This delegate can reference any method that has one string parameter and doesn&#8217;t return a result.\u00a0<\/p>\n<p>Additionally, we can take a look at the delegate syntax:<\/p>\n<p><code>[access modifier] delegate [return type] [delegate name]([parameters])<\/code><\/p>\n<p>With that out of the way, let&#8217;s see how we can instantiate a delegate.<\/p>\n<h2><a id=\"instantiatingdelegates\"><\/a>Instantiating Delegates<\/h2>\n<p>Let&#8217;s define a method that this delegate can point to:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void WriteText(string text) =&gt; Console.WriteLine($\"Text:\u00a0{text}\");<\/code><\/p>\n<p>Now we can instantiate the delegate in a few different ways:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var delegate1 = new PrintMessage(WriteText);<\/code><\/p>\n<p>There&#8217;s also a shorter version of the same syntax:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var delegate2 = WriteText;<\/code><\/p>\n<p>And we can do it with an anonymous method as well:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var delegate3 = delegate(string text)\r\n    { Console.WriteLine($\"Text: {text}\"); };<\/pre>\n<p>Or even more concisely with a lambda method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">PrintMessage delegate4 = text =&gt;  \r\n    {\u00a0Console.WriteLine($\"Text:\u00a0{text}\");\u00a0};<\/pre>\n<p>As you can see, the last two examples don&#8217;t need our method, we can just add the implementation directly. The last example is probably something you&#8217;re used to seeing most of the time since it&#8217;s the most modern approach (C# 3 onwards).<\/p>\n<p><strong>For a more structured code base, we would use the first two approaches, and if we want a quick solution we would use the third and the fourth approach.<\/strong><\/p>\n<h2><a id=\"invokingdelegates\"><\/a>Invoking Delegates<\/h2>\n<p>Delegates can be invoked by using the <code>Invoke()<\/code> method:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">delegate1.Invoke(\"Go ahead, make my day.\");<\/code><\/p>\n<p>or just by invoking the delegate directly using <code>()<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">delegate1(\"Go ahead, make my day.\");<\/code><\/p>\n<p>This results in the text being printed to the console:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Text: Go ahead, make my day.\r\nText: You're gonna need a bigger boat.<\/pre>\n<p>That&#8217;s all there is to it.<\/p>\n<p>Or is it?<\/p>\n<h2><a id=\"multicastingdelegates\"><\/a>Multicasting Delegates<\/h2>\n<p>Delegates are even more powerful than that. <strong>One delegate can reference multiple different methods.<\/strong> <strong>These delegates are called multicast delegates.<\/strong><\/p>\n<p>We&#8217;ve printed some text to the console. Let&#8217;s say we need to print it in the reverse order as well. Let&#8217;s create that does that:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void ReverseWriteText(string text) =&gt; Console.WriteLine($\"Text in reverse:\u00a0{Reverse(text)}\");\r\n\r\nprivate static string Reverse(string s)\r\n{\r\n    char[] charArray = s.ToCharArray();\r\n    Array.Reverse(charArray);\r\n    return new string(charArray);\r\n}<\/pre>\n<p>And then we can implement the multicast delegate in two different ways. We can create a delegate that&#8217;s the combination of the existing ones:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var delegate1 = new PrintMessage(WriteText);\r\nvar delegate2 = new PrintMessage(ReverseWriteText);\r\n\/\/ with + sign\r\nvar multicastDelegate = delegate1 + delegate2;\r\n\r\nmulticastDelegate.Invoke(\"Go ahead, make my day.\");\r\nmulticastDelegate(\"You're gonna need a bigger boat.\");<\/pre>\n<p>This prints out:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Text:\u00a0Go ahead, make my day.\r\nText in reverse:\u00a0.yad ym ekam ,daeha oG\r\nText:\u00a0You're gonna need a bigger boat.\r\nText in reverse:\u00a0.taob reggib a deen annog er'uoY<\/pre>\n<p>We can also use the = and += to achieve the same thing:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var delegate1 = new PrintMessage(WriteText);\r\nvar delegate2 = new PrintMessage(ReverseWriteText);\r\n\r\n\/\/ with =, +=, and -=\r\nmulticastDelegate = delegate1;\r\nmulticastDelegate += delegate2;\r\n\r\nmulticastDelegate.Invoke(\"Go ahead, make my day.\");\r\nmulticastDelegate(\"You're gonna need a bigger boat.\");<\/pre>\n<p>The result is exactly the same.<\/p>\n<h2><a id=\"genericdelegates\"><\/a>Generic Delegates<\/h2>\n<p><strong>We can make our delegates even more useful, by extending them with generic types.<\/strong><\/p>\n<p>We can create a generic delegate:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">delegate T Print&lt;T&gt;(T param1);<\/code><\/p>\n<p>This delegate both accepts and returns generic types.\u00a0<\/p>\n<p>Let&#8217;s say we have a method that accepts a string and then returns a reversed string to the caller:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static string ReverseText(string text) =&gt; Reverse(text);<\/code><\/p>\n<p>While instantiating generic delegates we need to declare the concrete types:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Print&lt;string&gt; delegate3 = new Print&lt;string&gt;(ReverseText);\r\nConsole.WriteLine(delegate3(\"I'll be back.\"));<\/pre>\n<p>This prints out the reversed string as expected:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">.kcab eb ll'I<\/code><\/p>\n<p>But now we&#8217;re not bound to use just strings, we can use anything we like, even the complex objects. The implementation is entirely up to the methods we reference.<\/p>\n<h2><a id=\"actionfunc\"><\/a>Action&lt;T&gt; and Func&lt;T&gt; Delegates<\/h2>\n<p>Now that we know how to create generic delegates, we can mention <strong><code>Func&lt;T&gt;<\/code>, and\u00a0 <code>Action&lt;T&gt;<\/code> delegates readily available within the .NET framework.<\/strong> These delegates already do what we&#8217;ve done manually with delegates so far.<\/p>\n<p>In our case, we can use the <code>Action&lt;T&gt;<\/code> delegate to encapsulate the <code>ReverseWriteText<\/code> method with no return types, or the <code>Func&lt;T&gt;<\/code> delegate to encapsulate the <code>ReverseText<\/code> method because it has a return type.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Action&lt;string&gt; executeReverseWrite = ReverseWriteText;\r\nexecuteReverseWrite(\"Are you not entertained?\");\r\n\r\nFunc&lt;string, string&gt; executeReverse = ReverseText;\r\nConsole.WriteLine(executeReverse(\"Are you not entertained?\")); <\/pre>\n<p>The results are exactly the same as before.<\/p>\n<p>Now we can go ahead and create all sorts of useful methods. For example, the useful <code>Where()<\/code> Linq extension method uses the Func delegate:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static IEnumerable&lt;TSource&gt; Where&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, Func&lt;TSource, bool&gt; predicate);<\/code><\/p>\n<p>Say we have a list of strings. We can easily extract all the strings that contain the specific substring:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var stringList = new List&lt;string&gt;();\r\nstringList.Where(x =&gt; x.Contains(\"some text\"));<\/pre>\n<p>The <code>Contains()<\/code> method evaluates the expression, and returns the source (string in this case) if it fulfills the condition, which is in this case that the string contains &#8220;some text&#8221;. We&#8217;ll end up with the <code>IEnumerable&lt;string&gt;<\/code> of all the strings that contain the phrase &#8220;some text&#8221;.<\/p>\n<h2>Conclusion<\/h2>\n<p>Delegates are an exceptionally useful concept in C#. Once you wrap your head around them, you can use them in all kinds of scenarios and create more modular and flexible applications. We&#8217;ve seen how we can declare, instantiate, use, and multicast delegates. Then we&#8217;ve introduced the generic delegates which we see all around the codebases, sometimes even without noticing them.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;re going to talk about C# delegates, which are a prerequisite for learning events-based programming. Delegates are one of the fundamental building blocks of flexible applications, as they can be found in the vast majority of .NET framework code base and client libraries. \u00a0 What is a C# Delegate? A C# delegate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":60290,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[384,937,950,951,953,952,954],"class_list":["post-58991","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-action","tag-delegates","tag-function","tag-generic-delegates","tag-instantiating-delegates","tag-invoking-delegates","tag-multicasting-delegates","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Delegates - Code Maze<\/title>\n<meta name=\"description\" content=\"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/delegates-charp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Delegates - Code Maze\" \/>\n<meta property=\"og:description\" content=\"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/delegates-charp\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-09T06:00:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-21T11:46:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vladimir Pecanac\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/PecanacVladimir\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vladimir Pecanac\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/\"},\"author\":{\"name\":\"Vladimir Pecanac\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/50de31ad4e1992752e972e4715d93739\"},\"headline\":\"C# Delegates\",\"datePublished\":\"2021-11-09T06:00:52+00:00\",\"dateModified\":\"2021-12-21T11:46:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/\"},\"wordCount\":802,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png\",\"keywords\":[\"action\",\"delegates\",\"Function\",\"Generic Delegates\",\"Instantiating Delegates\",\"Invoking Delegates\",\"Multicasting Delegates\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/delegates-charp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/\",\"url\":\"https:\/\/code-maze.com\/delegates-charp\/\",\"name\":\"C# Delegates - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png\",\"datePublished\":\"2021-11-09T06:00:52+00:00\",\"dateModified\":\"2021-12-21T11:46:34+00:00\",\"description\":\"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/delegates-charp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png\",\"width\":1100,\"height\":620,\"caption\":\"delegates\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/delegates-charp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Delegates\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/50de31ad4e1992752e972e4715d93739\",\"name\":\"Vladimir Pecanac\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2016\/02\/profile_image-100x100.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2016\/02\/profile_image-100x100.png\",\"caption\":\"Vladimir Pecanac\"},\"description\":\"Hi, my name is Vladimir Pecanac, and I am a full-time .NET developer and DevOps enthusiast. I created this blog so I can share the things I learn in the hope of both helping others and deepening my own knowledge of the topics I write about. The best way to learn is to teach.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/vladimir-pecanac\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/PecanacVladimir\"],\"url\":\"https:\/\/code-maze.com\/author\/codemaze_blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Delegates - Code Maze","description":"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/delegates-charp\/","og_locale":"en_US","og_type":"article","og_title":"C# Delegates - Code Maze","og_description":"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.","og_url":"https:\/\/code-maze.com\/delegates-charp\/","og_site_name":"Code Maze","article_published_time":"2021-11-09T06:00:52+00:00","article_modified_time":"2021-12-21T11:46:34+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png","type":"image\/png"}],"author":"Vladimir Pecanac","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/PecanacVladimir","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Vladimir Pecanac","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/delegates-charp\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/delegates-charp\/"},"author":{"name":"Vladimir Pecanac","@id":"https:\/\/code-maze.com\/#\/schema\/person\/50de31ad4e1992752e972e4715d93739"},"headline":"C# Delegates","datePublished":"2021-11-09T06:00:52+00:00","dateModified":"2021-12-21T11:46:34+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/delegates-charp\/"},"wordCount":802,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/delegates-charp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png","keywords":["action","delegates","Function","Generic Delegates","Instantiating Delegates","Invoking Delegates","Multicasting Delegates"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/delegates-charp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/delegates-charp\/","url":"https:\/\/code-maze.com\/delegates-charp\/","name":"C# Delegates - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/delegates-charp\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/delegates-charp\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png","datePublished":"2021-11-09T06:00:52+00:00","dateModified":"2021-12-21T11:46:34+00:00","description":"C# delegates are one of the basic building blocks of flexible applications. They can be found in the majority of the .NET framework codebase.","breadcrumb":{"@id":"https:\/\/code-maze.com\/delegates-charp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/delegates-charp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/delegates-charp\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/11\/delegates.png","width":1100,"height":620,"caption":"delegates"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/delegates-charp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"C# Delegates"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/50de31ad4e1992752e972e4715d93739","name":"Vladimir Pecanac","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2016\/02\/profile_image-100x100.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2016\/02\/profile_image-100x100.png","caption":"Vladimir Pecanac"},"description":"Hi, my name is Vladimir Pecanac, and I am a full-time .NET developer and DevOps enthusiast. I created this blog so I can share the things I learn in the hope of both helping others and deepening my own knowledge of the topics I write about. The best way to learn is to teach.","sameAs":["https:\/\/www.linkedin.com\/in\/vladimir-pecanac\/","https:\/\/x.com\/https:\/\/twitter.com\/PecanacVladimir"],"url":"https:\/\/code-maze.com\/author\/codemaze_blog\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/58991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=58991"}],"version-history":[{"count":18,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/58991\/revisions"}],"predecessor-version":[{"id":62050,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/58991\/revisions\/62050"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/60290"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=58991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=58991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=58991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}