<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2558285792471038294</id><updated>2024-09-06T17:19:13.697-07:00</updated><category term=".NET Extension Methods"/><category term="Extending Base Type Functionality with Extension Methods"/><category term="Extension method syntax in VB.Net and C#.Net"/><category term="extend existing type without inheritance"/><category term="extending existing type"/><title type='text'>Extension Methods in .NET</title><subtitle type='html'>This post explains the extension method feature in .NET framework(.Net 3.5 and above). You can extend the Base Type Functionality with Extension Methods.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://methodextension.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2558285792471038294/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://methodextension.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13112817201598525701</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9DeunJL3tqvFJaq6MASKFPsv0aHmViCJ1thnEdde0kOb9fpdeh1ooiF6xPqiukdLspnzYlgn3MBHqAIHdZ_1lAGFX0NQb1ckUqZj3e3n5mVEvSVhphcyt1SZ41pcql9o/s220/ProfilePhoto.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2558285792471038294.post-1341367714956589030</id><published>2012-04-14T12:02:00.000-07:00</published><updated>2012-06-23T00:54:33.041-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET Extension Methods"/><category scheme="http://www.blogger.com/atom/ns#" term="extend existing type without inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="Extending Base Type Functionality with Extension Methods"/><category scheme="http://www.blogger.com/atom/ns#" term="extending existing type"/><category scheme="http://www.blogger.com/atom/ns#" term="Extension method syntax in VB.Net and C#.Net"/><title type='text'>Extension Methods in .NET</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 3;&quot;&gt;
&lt;a href=&quot;http://www.blogger.com/&quot; name=&quot;what&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #004cd5; font-family: Verdana, sans-serif;&quot;&gt;&lt;span style=&quot;color: #134f5c;&quot;&gt;What are Extension Methods?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;span style=&quot;color: #ff9900; font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;span style=&quot;color: black; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt;&quot;&gt;Extension methods enable you to &quot;add&quot; methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt;&quot;&gt;
&lt;strong&gt;&lt;span style=&quot;font-family: &#39;Segoe UI&#39;;&quot;&gt;&lt;span style=&quot;color: #134f5c;&quot;&gt;&lt;span class=&quot;lwcollapsibleareatitle1&quot;&gt;&lt;span style=&quot;font-size: 14.5pt; line-height: 115%;&quot;&gt;Binding Extension Methods at Compile Time&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 115%;&quot;&gt;You can use extension methods to extend a class or interface, but not to override them. An extension method with the same name and signature as an interface or class method will never be called. At compile time, extension methods always have lower priority than instance methods defined in the type itself.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 125%; margin: 0in 0in 0pt; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt;With traditional object-oriented development, extending classes is typically achieved by deriving from a base class and enhancing the functionality in the derived class. Visual Basic&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 6.5pt; line-height: 125%;&quot;&gt;®&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt; still supports these object-oriented concepts, but classes are sometimes marked NotInheritable to prevent modification of their behavior through inheritance. As a result, there is no way to customize these classes. An example of this is the System.String class.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 125%; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt;A new feature made available in Visual Basic 2008, however, lets you extend any existing type&#39;s functionality, even when a type is not inheritable. And these extension methods play a crucial role in the implementation of LINQ.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 125%; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt;Extension methods provide a simple mechanism to extend types in the system (value, reference, and interface types) with new methods. These methods extend the original type and can be called like regular, defined instance methods, but they leave the original type and its methods untouched. Extension methods create the illusion that they are defined on a real type, but, in reality, no changes are made to the original types.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;

&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; line-height: 125%;&quot;&gt;&lt;span style=&quot;color: #134f5c;&quot;&gt;Performance &lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 125%; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt;Performance is relatively unaffected. Even though your Visual Basic source code may look different, it compiles to a simple shared method call and generates the same IL as if you had used the shared method call. So there is no performance hit through using them.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: 125%; margin: 0in 0in 0pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Segoe UI&#39;, sans-serif; font-size: 9.5pt; line-height: 125%;&quot;&gt;&lt;/span&gt;&amp;nbsp; &lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;line-height: normal; margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;extension methods are not a replacement for object-oriented concepts. If you are familiar with object-oriented concepts and have a well-designed application, you are probably already using inheritance somewhere in your application and should continue doing so. You probably own many of the types you are using, meaning you have access to the source code and can extend the functionality through normal object-oriented concepts. Extension methods really provide a way to enhance classes that you previously could not extend. Extension methods should be used sparingly, when other approaches are not possible or suitable.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Calibri;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Writing Extension Methods:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;The basic outline of creating an extension methods goes something like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ol type=&quot;1&quot;&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Create a &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;public static&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; class (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;module&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; in VB)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Define functions&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-list: l0 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;&quot;&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;Make the functions an extension method&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;1. Create a &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;public static&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; class (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;module&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; in VB)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); margin-left: 0.5in; margin-right: 0in; padding: 5pt;&quot;&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;border: medium none; line-height: normal; margin: 5pt 0in; padding: 0in;&quot;&gt;
&lt;i&gt;&lt;span lang=&quot;CS&quot; style=&quot;background-color: #d0e0e3; color: green; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;// C#&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;border: medium none; line-height: normal; margin: 5pt 0in; padding: 0in;&quot;&gt;
&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span lang=&quot;CS&quot; style=&quot;color: blue; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;public&lt;/span&gt;&lt;span lang=&quot;CS&quot; style=&quot;font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; MyExtensions&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;border: medium none; line-height: normal; margin: 5pt 0in; padding: 0in;&quot;&gt;
&lt;span lang=&quot;CS&quot; style=&quot;font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; color: black;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot; style=&quot;border: medium none; line-height: normal; margin: 5pt 0in; padding: 0in;&quot;&gt;
&lt;span lang=&quot;CS&quot; style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;margin: 0in 0in 10pt 0.5in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;code-comment1&quot;&gt;&lt;em&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&#39; VB&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Module&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; MyExtensions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black; font-size: x-small;&quot;&gt;End Module&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoListParagraph&quot; style=&quot;margin: 0in 0in 10pt 0.5in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt 0.25in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;2. Define functions &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;pre&gt;&lt;i&gt;&lt;span lang=&quot;CS&quot; style=&quot;color: green;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;// C#&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class=&quot;code-keyword1&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; MyExtensions&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; GetFirstCharacter(&lt;/span&gt;&lt;span class=&quot;code-sdkkeyword1&quot;&gt;&lt;span style=&quot;color: #339999;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(str.Length &amp;lt; 1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str.Substring(&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot; style=&quot;margin: 0in 0in 0pt 0.5in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot; style=&quot;margin: 0in 0in 10pt 0.5in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;code-comment1&quot;&gt;&lt;em&gt;&lt;span style=&quot;color: green;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&#39; VB&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Module&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; MyExtensions&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Public&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; GetFirstCharacter(&lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Byval&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;As&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;As&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;If&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (str.Length &amp;lt; &lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Then&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str.SubString(&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;If&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;code-keyword1&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;Module&lt;/span&gt;&lt;span style=&quot;background-color: #fbedbb;&quot;&gt;&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Calibri; font-size: small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt 0.25in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;3. Make the functions an extension method&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: normal; margin: 0in 0in 10pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;To make our C# version of our function, we need an extension method to mark the function as &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;static &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;(so that it can be accessed at any time without the need for declaring anything) and secondly, mark the first parameter with the &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; keyword. This keyword basically tells the CLR that when this extension method is called, to use &quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #990000; font-family: &#39;Courier New&#39;;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&quot; parameter as the source. See the following:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;pre&gt;&lt;i&gt;&lt;span lang=&quot;CS&quot; style=&quot;color: green;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;// C#&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class=&quot;code-keyword1&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; MyExtensions&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; GetFirstCharacter(&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-sdkkeyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: #339999;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; str)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(str.Length &amp;lt; 1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str.Substring(&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;color: black; font-family: Calibri;&quot;&gt;Now for the VB version. Instead of using the &lt;/span&gt;&lt;code&gt;&lt;span style=&quot;color: #990000;&quot;&gt;this&lt;/span&gt;&lt;/code&gt;&lt;span style=&quot;color: black; font-family: Calibri;&quot;&gt; keyword, we need to do something slightly different. We need to mark the function with the &lt;/span&gt;&lt;code&gt;&lt;span style=&quot;color: #990000;&quot;&gt;System.Runtime.CompilerServices.Extension&lt;/span&gt;&lt;/code&gt;&lt;span style=&quot;color: black; font-family: Calibri;&quot;&gt; attribute like so&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;pre&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&amp;lt;System.Runtime.CompilerServices.Extension&amp;gt; _&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: windowtext;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Public&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; GetFirstCharacter(&lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Byval&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;As&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;As&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;If&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; (str.Length &amp;lt; &lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;) &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Then&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; str.SubString(&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;code-digit1&quot;&gt;&lt;span style=&quot;color: navy;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;If&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;code-keyword1&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; tab-stops: 72.75pt;&quot;&gt;
&lt;span style=&quot;color: black; font-family: Calibri; font-size: small;&quot;&gt;Now you can use this method in your project&amp;nbsp; as follows&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;border: medium none; line-height: normal; margin: 0in 0in 0pt; padding: 0in;&quot;&gt;
&lt;i&gt;&lt;span lang=&quot;CS&quot; style=&quot;background-color: #cfe2f3; color: green; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;// C#&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: #cfe2f3; font-size: x-small;&quot;&gt;&lt;span class=&quot;code-sdkkeyword1&quot;&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: #339999;&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;CS&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; str = &lt;/span&gt;&lt;span class=&quot;code-string1&quot;&gt;&lt;span style=&quot;color: purple;&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;border: medium none; line-height: normal; margin: 0in 0in 5pt; padding: 0in;&quot;&gt;
&lt;span lang=&quot;CS&quot; style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;str = str.GetFirstCharacter();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 10pt; text-indent: 0.5in;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-position: initial initial; background-repeat: initial initial; border: 1pt solid rgb(251, 237, 187); padding: 5pt;&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;border: medium none; line-height: normal; margin: 0in 0in 0pt; padding: 0in;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;background-color: #cfe2f3; color: green; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&#39; VB&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;border: medium none; line-height: normal; margin: 0in 0in 5pt; padding: 0in;&quot;&gt;
&lt;span style=&quot;background-color: #cfe2f3;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;Dim&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt; str &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;&lt;span class=&quot;code-string1&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Calibri;&quot;&gt; &lt;span lang=&quot;CS&quot;&gt;Hello&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: purple; font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;; font-size: 9pt;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;border: medium none; line-height: normal; margin: 0in 0in 5pt; padding: 0in;&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;background-color: #cfe2f3; color: black;&quot;&gt;&lt;span style=&quot;font-family: Calibri;&quot;&gt;str = str.&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Times New Roman&#39;, serif; font-size: 12pt;&quot;&gt; &lt;span lang=&quot;CS&quot;&gt;GetFirstCharacter&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Calibri;&quot;&gt;&lt;span lang=&quot;CS&quot;&gt; &lt;/span&gt;()&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Please let me know if it helps or if you have any queries...&lt;br /&gt;
References :&lt;br /&gt;
&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb383977.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/cc163317.aspx&quot;&gt;http://msdn.microsoft.com/en-us/magazine/cc163317.aspx&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://methodextension.blogspot.com/feeds/1341367714956589030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://methodextension.blogspot.com/2012/04/extension-methods-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2558285792471038294/posts/default/1341367714956589030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2558285792471038294/posts/default/1341367714956589030'/><link rel='alternate' type='text/html' href='http://methodextension.blogspot.com/2012/04/extension-methods-in-net.html' title='Extension Methods in .NET'/><author><name>Narendra</name><uri>http://www.blogger.com/profile/13112817201598525701</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='15' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9DeunJL3tqvFJaq6MASKFPsv0aHmViCJ1thnEdde0kOb9fpdeh1ooiF6xPqiukdLspnzYlgn3MBHqAIHdZ_1lAGFX0NQb1ckUqZj3e3n5mVEvSVhphcyt1SZ41pcql9o/s220/ProfilePhoto.jpg'/></author><thr:total>0</thr:total></entry></feed>