Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php on line 1077

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php on line 1077

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php on line 1079

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php on line 1079

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php on line 1079

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home3/weo2000/public_html/offeman.com/wp-content/plugins/backup/com/core/functions.php:1077) in /home3/weo2000/public_html/offeman.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":83,"date":"2011-04-19T04:31:27","date_gmt":"2011-04-19T04:31:27","guid":{"rendered":"http:\/\/www.offeman.com\/2011\/04\/19\/ExtensionMethodsInC.aspx"},"modified":"2011-04-19T04:31:27","modified_gmt":"2011-04-19T04:31:27","slug":"extension-methods-in-c","status":"publish","type":"post","link":"https:\/\/offeman.com\/extension-methods-in-c\/","title":{"rendered":"Extension methods in C#"},"content":{"rendered":"

Wikipedia has a very good overview of extension methods in C# here<\/a>.<\/p>\n

Basically, if you create a static method in a static class and the first parameter includes the keyword \u2018this\u2019 then the first parameter will be the calling object and you\u2019ve created an extension method.<\/p>\n

Here is a quick example console application (based on the example from Wikipedia):<\/p>\n

using <\/span>System;\r\nusing <\/span>System.Collections.Generic;\r\nusing <\/span>System.Linq;\r\nusing <\/span>System.Text;\r\n\r\nnamespace <\/span>ConsoleApplication1\r\n{\r\n    class <\/span><\/font>Program\r\n    <\/span>{\r\n        static void <\/span>Main(string<\/span>[] args)\r\n        {\r\n            Console<\/span>.WriteLine("abcdefg"<\/span>.ExtReverse());\r\n            Console<\/span>.ReadLine();\r\n        }\r\n    }\r\n\r\n    public static class <\/span><\/font>ExampleExtension\r\n    <\/span>{\r\n        public static string <\/span>ExtReverse(this string <\/span>input)\r\n        {\r\n            char<\/span>[] chars = input.ToCharArray();\r\n            Array<\/span>.Reverse(chars);\r\n            return new <\/span>String<\/span>(chars);\r\n        }\r\n    }\r\n}<\/font><\/pre>\n","protected":false},"excerpt":{"rendered":"

Wikipedia has a very good overview of extension methods in C# here. Basically, if you create a static method in a static class and the first parameter includes the keyword \u2018this\u2019 then the first parameter will be the calling object and you\u2019ve created an extension method. Here is a quick example console application (based on […]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/posts\/83"}],"collection":[{"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":0,"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"wp:attachment":[{"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/offeman.com\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}