<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Lars-Erik Kindblad</title>
	<atom:link href="http://www.kindblad.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kindblad.com</link>
	<description>Writing about programming, Buddhism &#38; life</description>
	<pubDate>Fri, 26 Sep 2008 14:08:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>How to get rid of the alert &#8220;The following module was built either with optimizations enabled or without debug information&#8221;</title>
		<link>http://www.kindblad.com/2008/09/26/how-to-get-rid-of-the-alert-the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/</link>
		<comments>http://www.kindblad.com/2008/09/26/how-to-get-rid-of-the-alert-the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 14:08:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=56</guid>
		<description><![CDATA[If you have a solution in Visual Studio which consists of both web- and class library projects, then you might get an alert box with the following message:
"The following module was built either with optimizations enabled or without debug information:

....

To debug this module, change its project build configuration to Debug mode. To suppress this message, [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a solution in Visual Studio which consists of both web- and class library projects, then you might get an alert box with the following message:</p>
<pre><code>"The following module was built either with optimizations enabled or without debug information:

....

To debug this module, change its project build configuration to Debug mode. To suppress this message, disable the 'Warn if no user code on launch' debugger option."</code></pre>
<p>Do this to get rid of the alert:<br />
1. Right click the project giving the alert, choose &#8220;Properties&#8221;.<br />
2. Choose &#8220;Build&#8221; and then &#8220;Advanced&#8230;&#8221;<br />
3. Set Debug info to &#8220;full&#8221;.</p>
<p>Now the alert should be gone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/09/26/how-to-get-rid-of-the-alert-the-following-module-was-built-either-with-optimizations-enabled-or-without-debug-information/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Response.Redirect not working within an UpdatePanel?</title>
		<link>http://www.kindblad.com/2008/09/26/responseredirect-not-working-within-an-updatepanel/</link>
		<comments>http://www.kindblad.com/2008/09/26/responseredirect-not-working-within-an-updatepanel/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 09:29:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=55</guid>
		<description><![CDATA[If you get an exception when doing a Response.Redirect within an UpdatePanel then you are most probably missing the following lines in your web.config:
&#60;httpModules&#62;
  &#60;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&#62;
&#60;/httpModules&#62;
]]></description>
			<content:encoded><![CDATA[<p>If you get an exception when doing a Response.Redirect within an UpdatePanel then you are most probably missing the following lines in your web.config:</p>
<pre><code>&lt;httpModules&gt;
  &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
&lt;/httpModules&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/09/26/responseredirect-not-working-within-an-updatepanel/feed/</wfw:commentRss>
		</item>
		<item>
		<title>FCKEditor 2.x: How to add a new button with custom javascript to the toolbar</title>
		<link>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-add-a-new-button-with-custom-javascript-to-the-toolbar/</link>
		<comments>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-add-a-new-button-with-custom-javascript-to-the-toolbar/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 09:51:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=54</guid>
		<description><![CDATA[In this tutorial we will have a look at how to add a new button with custom javascript to a FCKeditor toolbar. In this example our custom button will simply open a link in a new window when it&#8217;s clicked.
1. Start by finding the &#8220;plugins&#8221; folder which is located below the &#8220;fckeditor\editor&#8221; folder.
2. Create a [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we will have a look at how to add a new button with custom javascript to a FCKeditor toolbar. In this example our custom button will simply open a link in a new window when it&#8217;s clicked.<span id="more-54"></span></p>
<p>1. Start by finding the &#8220;plugins&#8221; folder which is located below the &#8220;fckeditor\editor&#8221; folder.<br />
2. Create a new folder, name it &#8220;openurl&#8221;.<br />
3. Add an icon within the &#8220;openurl&#8221; folder, name it &#8220;openurl.gif&#8221;.<br />
4. Create a new file within the &#8220;openurl&#8221; folder, name it &#8220;fckplugin.js&#8221;, and add the following code:</p>
<pre><code>// Our method which is called during initialization of the toolbar.
function OpenUrl()
{
}

// Disable button toggling.
OpenUrl.prototype.GetState = function()
{
	return FCK_TRISTATE_OFF;
}

// Our method which is called on button click.
OpenUrl.prototype.Execute = function()
{
	window.open('http://www.kindblad.com');
}

// Register the command.
FCKCommands.RegisterCommand('openurl', new OpenUrl());

// Add the button.
var item = new FCKToolbarButton('openurl', 'Open URL');
item.IconPath = FCKPlugins.Items['openurl'].Path + 'openurl.gif';
FCKToolbarItems.RegisterItem('openurl', item);</code></pre>
<p>5. Now we need to define where we want our button to be shown in the toolbar. Open up &#8220;fckeditor\fckconfig.js&#8221; and look for:</p>
<pre><code>FCKConfig.ToolbarSets["Default"] = [
	['Source'],
	['Cut','Copy','Paste','PasteText','PasteWord','-','SpellCheck'],
	...</code></pre>
<p>Add &#8216;openurl&#8217; anywhere in the toolbar definition, e.g.:</p>
<pre><code>FCKConfig.ToolbarSets["Default"] = [
	['openurl,'Source'],
	['Cut','Copy','Paste','PasteText','PasteWord','-','SpellCheck'],
	...</code></pre>
<p>6. And lastly, we need to tell FCKeditor to load our plugin, we do this by finding the following string in the &#8220;fckeditor/fckconfig.js&#8221;.</p>
<pre><code>FCKConfig.PluginsPath = FCKConfig.BasePath + 'plugins/' ;</code></pre>
<p>Add the following code below the line above:</p>
<pre><code>FCKConfig.Plugins.Add('openurl');</code></pre>
<p>That&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-add-a-new-button-with-custom-javascript-to-the-toolbar/feed/</wfw:commentRss>
		</item>
		<item>
		<title>FCKeditor 2.x: How to get an instance of the editor using javascript</title>
		<link>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-get-an-instance-of-the-editor-using-javascript/</link>
		<comments>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-get-an-instance-of-the-editor-using-javascript/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 08:42:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=53</guid>
		<description><![CDATA[This is how you get an instance of the editor when you are within the page that loads the editor:
FCKeditorAPI.GetInstance([instanceName]);
E.g.:
var editor = FCKeditorAPI.GetInstance('ctrArticle');
And this is how you get the editor instance when you are inside the editor instance:
var editor = FCK;
And lastly, this is how you get the name (DOM id) of the editor instance [...]]]></description>
			<content:encoded><![CDATA[<p>This is how you get an instance of the editor when you are within the page that loads the editor:<span id="more-53"></span></p>
<pre><code>FCKeditorAPI.GetInstance([instanceName]);</code></pre>
<p>E.g.:</p>
<pre><code>var editor = FCKeditorAPI.GetInstance('ctrArticle');</code></pre>
<p>And this is how you get the editor instance when you are inside the editor instance:</p>
<pre><code>var editor = FCK;</code></pre>
<p>And lastly, this is how you get the name (DOM id) of the editor instance (get the instance using either of the methods above):</p>
<pre><code>alert(editor.Name);</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/09/07/fckeditor-2x-how-to-get-an-instance-of-the-editor-using-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A short review of Google Chrome</title>
		<link>http://www.kindblad.com/2008/09/02/a-short-review-of-google-chrome/</link>
		<comments>http://www.kindblad.com/2008/09/02/a-short-review-of-google-chrome/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 20:42:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Other software]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=46</guid>
		<description><![CDATA[Google just released their new web browser Google Chrome. Here&#8217;s my thoughts after using it for a few hours.
- Small download, fast install.
- Very fast startup.
- Compact and slick user interface which gives you more space.
- Any tab element can be detached into a separate window, and a separate window can be re-attached to the [...]]]></description>
			<content:encoded><![CDATA[<p>Google just released their new web browser Google Chrome. Here&#8217;s my thoughts after using it for a few hours.<span id="more-46"></span></p>
<p>- Small download, fast install.<br />
- Very fast startup.<br />
- Compact and slick user interface which gives you more space.<br />
- Any tab element can be detached into a separate window, and a separate window can be re-attached to the tab.<br />
- &#8220;Porn mode&#8221; - A new window called &#8220;incognito&#8221; can be opened. This window won&#8217;t leave any traces in the browser- or search history, and cookies will be deleted when the window is closed.<br />
- &#8220;Create application shortcut&#8221; - Create a shortcut to the current page on your start menu, quick lunch or desktop.<br />
- Render sites really well.<br />
- Built in task manager which shows how much CPU, memory and network each tab uses.<br />
- One tab = one process. If one tab crashes it doesn&#8217;t effect all the tabs within the same window.<br />
- Nifty DOM inspector which has most of the Firebug features.</p>
<p>Some screenshots:</p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-1.png" alt="" title="Google Chrome" class="alignnone size-medium wp-image-47" /></p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-2.png" alt="Google Chrome" title="Google Chrome" class="alignnone size-medium wp-image-48" /></p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-3.png" alt="Google Chrome" title="google-chrome-3" class="alignnone size-medium wp-image-49" /></p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-4.png" alt="Google Chrome" title="google-chrome-4" class="alignnone size-medium wp-image-50" /></p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-5.png" alt="Google Chrome" title="google-chrome-5" class="alignnone size-medium wp-image-51" /></p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/09/google-chrome-6.png" alt="Google Chrome" title="google-chrome-6" class="alignnone size-medium wp-image-52" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/09/02/a-short-review-of-google-chrome/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to convert from string to enum using C# and generics</title>
		<link>http://www.kindblad.com/2008/08/18/how-to-convert-from-string-to-enum-using-c-and-generics/</link>
		<comments>http://www.kindblad.com/2008/08/18/how-to-convert-from-string-to-enum-using-c-and-generics/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 20:13:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=45</guid>
		<description><![CDATA[In order to convert from a string to an enumeration in .NET you can use the method Enum.Parse as follows:
public enum SortExpressions
{
	FirstNameAsc,
	FirstNameDesc,
	LastNameAsc,
	LastNameDesc
}

var value = "lastnameasc";
var sortExpression = (SortExpressions) Enum.Parse(typeof(SortExpressions), value, true);
Since this operation is often needed we should make a ConvertToEnum method so we can reuse it. But instead of returning it as the typical [...]]]></description>
			<content:encoded><![CDATA[<p>In order to convert from a string to an enumeration in .NET you can use the method Enum.Parse as follows:</p>
<pre><code>public enum SortExpressions
{
	FirstNameAsc,
	FirstNameDesc,
	LastNameAsc,
	LastNameDesc
}

var value = "lastnameasc";
var sortExpression = (SortExpressions) Enum.Parse(typeof(SortExpressions), value, true);</code></pre>
<p>Since this operation is often needed we should make a ConvertToEnum method so we can reuse it. But instead of returning it as the typical object type, we should rather use generics to return it as the actual type:<span id="more-45"></span></p>
<pre><code>/// &lt;summary&gt;
/// Converts a string to the specificed enumeration.
/// &lt;/summary&gt;
public T ConvertToEnum&lt;T&gt;(string value, T defaultEnum)
{
	value = value.Replace(" ", "").Trim();

	try
	{
		return (T) Enum.Parse(typeof(T), value, true);
	}
	catch
	{
		return defaultEnum;
	}
}</code></pre>
<p>A try/catch is used instead of the method Enum.IsDefined as it&#8217;s case-sensitive.</p>
<p>And this is how you can use our new ConvertToEnum method:</p>
<pre><code>var value = "lastnameasc";
var sortExpression = ConvertToEnum&lt;SortExpressions&gt;(value, SortExpressions.FirstNameAsc);</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/08/18/how-to-convert-from-string-to-enum-using-c-and-generics/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handling comma separated strings in stored procedures</title>
		<link>http://www.kindblad.com/2008/06/04/handling-comma-separated-strings-in-stored-procedures/</link>
		<comments>http://www.kindblad.com/2008/06/04/handling-comma-separated-strings-in-stored-procedures/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 22:19:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SQL Server]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=44</guid>
		<description><![CDATA[Imagine you have a user interface with a list of products. On the side of each product you have a delete checkbox and then a delete button below the list. Even though a user can delete multiple products at once, you only want to query the database once. One way to achieve this is by [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you have a user interface with a list of products. On the side of each product you have a delete checkbox and then a delete button below the list. Even though a user can delete multiple products at once, you only want to query the database once. One way to achieve this is by sending a comma separated string with product id&#8217;s to a stored procedure. The stored procedure will then loop through the string, grab each id and delete the corresponding row in the product table.<span id="more-44"></span></p>
<p>Here&#8217;s a stored procedure which does this:</p>
<pre><code>CREATE PROCEDURE DeleteProducts
(
	@values varchar(8000)
)
AS
BEGIN
	SET NOCOUNT ON;

	declare @value int
	declare @pos1 int
	declare @pos2 int

	-- Append , at the end of string.
	if substring(@values, len(@values), 1) &lt;&gt; ','
	begin
		set @values = @values + ','
	end

	-- First position.
	set @pos1 = 1
	set @pos2 = charindex(',', @values, 1)

	while (@pos1 &gt; 0 and @pos2 &gt; 0)
	begin
		set @value = cast(substring(@values, @pos1, @pos2 - @pos1) as int)

		delete from Product
		where ProductId = @value;

		-- Next position.
		set @pos1 = charindex(',', @values, @pos1) + 1
		set @pos2 = charindex(',', @values, @pos1)
	end
END</code></pre>
<p>And this is how you would execute it:</p>
<pre><code>exec DeleteProducts '1,20,30,100,250,1000';</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/06/04/handling-comma-separated-strings-in-stored-procedures/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Extending IDataReader implementations using extension methods</title>
		<link>http://www.kindblad.com/2008/05/12/extending-idatareader-using-extension-methods/</link>
		<comments>http://www.kindblad.com/2008/05/12/extending-idatareader-using-extension-methods/#comments</comments>
		<pubDate>Mon, 12 May 2008 12:31:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[datareader]]></category>

		<category><![CDATA[extension methods]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=43</guid>
		<description><![CDATA[In my post How to extend classes using extension methods, I write about how to extend classes with your own methods. This time we will extend the IDataReader interface with some new methods to save some typing. Since we extend the interface, our methods will be available in all the classes implementing the IDataReader interface, [...]]]></description>
			<content:encoded><![CDATA[<p>In my post <a href="http://www.kindblad.com/2008/05/04/how-to-extend-classes-using-extension-methods/" >How to extend classes using extension methods</a>, I write about how to extend classes with your own methods. This time we will extend the IDataReader interface with some new methods to save some typing. Since we extend the interface, our methods will be available in all the classes implementing the IDataReader interface, such as the SqlDataReader.<span id="more-43"></span></p>
<p>The IDataReader interface provides methods for getting field values for a given type:</p>
<pre><code>string email = reader.GetString(0);</code></pre>
<p>The problem with these methods are that they only accept the index-position and not the field name. Instead, I would prefer to write the code above like this:</p>
<pre><code>string email = reader.GetString("Email");</code></pre>
<p>In order to do this, we need to create a new static class, which defines some new extension methods:</p>
<pre><code>using System;
using System.Data;

/// &lt;summary&gt;
/// Provides extension methods for the IDataReader interface.
/// &lt;/summary&gt;
public static class IDataReaderExtension
{
	public static bool GetBoolean(this IDataReader reader, string name)
	{
		return (bool) reader[name];
	}
	public static Guid GetGuid(this IDataReader reader, string name)
	{
		return (Guid) reader[name];
	}
	public static int GetInt(this IDataReader reader, string name)
	{
		return (int) reader[name];
	}
	public static double GetDouble(this IDataReader reader, string name)
	{
		return (double) reader[name];
	}
	public static string GetString(this IDataReader reader, string name)
	{
		return (string) reader[name];
	}
	public static bool IsDBNull(this IDataReader reader, string name)
	{
		if (reader[name] == DBNull.Value)
			return true;

		return false;
	}
}</code></pre>
<p>Since we didn&#8217;t put our static class within a namespace, then our extension methods will be available at once. However, if you want to use a namespace, then you need to import the namespace in every class where you want to use these extension methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/05/12/extending-idatareader-using-extension-methods/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to add reflection to texts, shapes and pictures in Powerpoint 2007</title>
		<link>http://www.kindblad.com/2008/05/11/how-to-add-reflection-to-texts-shapes-and-pictures-in-powerpoint-2007/</link>
		<comments>http://www.kindblad.com/2008/05/11/how-to-add-reflection-to-texts-shapes-and-pictures-in-powerpoint-2007/#comments</comments>
		<pubDate>Sun, 11 May 2008 10:53:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Other software]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=38</guid>
		<description><![CDATA[
Text reflection:
1. Start by adding some text to your Powerpoint slide.
2. Select the text you want to add reflection to.
3. Click on the tab Format.
4. Select Text Effects, then Reflection and choose the reflection variant you prefer.

Shape reflection:
Same as text reflection, but choose Shape Effects instead.
Picture reflection:
Same as text reflection, but choose Picture Effects instead.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.kindblad.com/wp-content/uploads/2008/05/powerpoint-text-reflection.png" alt="" title="powerpoint-text-reflection" class="alignnone size-full wp-image-42" /><span id="more-38"></span></p>
<p>Text reflection:<br />
1. Start by adding some text to your Powerpoint slide.<br />
2. Select the text you want to add reflection to.<br />
3. Click on the tab Format.<br />
4. Select Text Effects, then Reflection and choose the reflection variant you prefer.</p>
<p><img src="http://www.kindblad.com/wp-content/uploads/2008/05/powerpoint-text-reflection-tutorial.png" alt="" title="powerpoint-text-reflection-tutorial" class="alignnone size-full wp-image-41" /></p>
<p>Shape reflection:<br />
Same as text reflection, but choose Shape Effects instead.</p>
<p>Picture reflection:<br />
Same as text reflection, but choose Picture Effects instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/05/11/how-to-add-reflection-to-texts-shapes-and-pictures-in-powerpoint-2007/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to extend classes using extension methods</title>
		<link>http://www.kindblad.com/2008/05/04/how-to-extend-classes-using-extension-methods/</link>
		<comments>http://www.kindblad.com/2008/05/04/how-to-extend-classes-using-extension-methods/#comments</comments>
		<pubDate>Sun, 04 May 2008 10:15:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.kindblad.com/?p=37</guid>
		<description><![CDATA[In .NET 3.5 there is a new functionality called extension methods. Extension methods let you extend any classes in the .NET framework, 3rd party frameworks or your own frameworks with your own static methods. Let&#8217;s look at an example where we extend the System.String class with two new methods, to get the first five and [...]]]></description>
			<content:encoded><![CDATA[<p>In .NET 3.5 there is a new functionality called extension methods. Extension methods let you extend any classes in the .NET framework, 3rd party frameworks or your own frameworks with your own static methods. <span id="more-37"></span>Let&#8217;s look at an example where we extend the System.String class with two new methods, to get the first five and last five characters of a string:</p>
<pre><code>public static class StringExtension
{
	/// &lt;summary&gt;
	/// Returns the first five characters of a string.
	/// &lt;/summary&gt;
	public static String GetFirstFiveCharacters(this String myString)
	{
		return myString.Substring(0, 5);
	}
	/// &lt;summary&gt;
	/// Returns the last five characters of a string.
	/// &lt;/summary&gt;
	public static String GetLastFiveCharacters(this String myString)
	{
		return myString.Substring(myString.Length - 5, 5);
	}
}</code></pre>
<p>In the example above, we use a class with the name StringExtension. However, you can name this class whatever you like: StringExtension, StringMethods, StringHelper, Helper etc. The only important thing is that your methods follow the pattern for extension methods:</p>
<pre><code>public static &lt;type&gt; MethodName(this &lt;type&gt; variableName)</code></pre>
<p>Now, let&#8217;s produce some code using our extension methods:</p>
<pre><code>String helloWorld = "Hello World";
String hello = helloWorld.GetFirstFiveCharacters(); // contains Hello
String world = helloWorld.GetLastFiveCharacters(); // contains World</code></pre>
<p>Of course, extension methods are shown in the intellisense in Visual Studio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kindblad.com/2008/05/04/how-to-extend-classes-using-extension-methods/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
