<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lummie.co.uk</title>
	<atom:link href="http://lummie.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://lummie.co.uk</link>
	<description>ubuntu, code and stuff</description>
	<lastBuildDate>Wed, 19 Oct 2011 23:47:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Happy 7th Birthday</title>
		<link>http://lummie.co.uk/happy-7th-birthday/</link>
		<comments>http://lummie.co.uk/happy-7th-birthday/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 23:47:09 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=432</guid>
		<description><![CDATA[Ubuntu is 7 today, so happy birthday to U. Thanks to Canonical and the community for making my computing life more inspiring and more productive.]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-433" title="ubuntu-logo" src="http://lummie.co.uk/wp-content/uploads/ubuntu-logo-150x150.png" alt="" width="150" height="150" />Ubuntu is 7 today, so happy birthday to U.</p>
<p>Thanks to Canonical and the community for making my computing life more inspiring and more productive.</p>
]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/happy-7th-birthday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check object instances are of a specific class or inherited from a specific class</title>
		<link>http://lummie.co.uk/how-to-check-object-instances-are-of-a-specific-class-or-inherited-from-a-specific-class/</link>
		<comments>http://lummie.co.uk/how-to-check-object-instances-are-of-a-specific-class-or-inherited-from-a-specific-class/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:40:31 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=416</guid>
		<description><![CDATA[You can determine if an object is of a specific class by using the typeof keyword. if &#40;myObj.GetType&#40;&#41; == typeof&#40;MyClass&#41;&#41; &#123; // Do something &#125; If you want to check to see if an object is of a specific type, &#8230; <a href="http://lummie.co.uk/how-to-check-object-instances-are-of-a-specific-class-or-inherited-from-a-specific-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You can determine if an object is of a specific class by using the typeof keyword.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>myObj<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>MyClass<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Do something</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>If you want to check to see if an object is of a specific type, or can be cast to a specific type then use the is operator.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>myObj <span style="color: #008000;">is</span> MyClass<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Do something</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/how-to-check-object-instances-are-of-a-specific-class-or-inherited-from-a-specific-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to override constructors and pass extra parameters</title>
		<link>http://lummie.co.uk/how-to-override-constructors-and-pass-extra-parameters/</link>
		<comments>http://lummie.co.uk/how-to-override-constructors-and-pass-extra-parameters/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:39:20 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=414</guid>
		<description><![CDATA[If you want to descend from a class that requires parameters passed in its constructor, and you wish to introduce extra parameters in the descendants constructor then when you define the derived classes constructor, simply add : base() to the &#8230; <a href="http://lummie.co.uk/how-to-override-constructors-and-pass-extra-parameters/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to descend from a class that requires parameters passed in its constructor, and you wish to introduce extra parameters in the descendants constructor then when you define the derived classes constructor, simply add <strong>: base()</strong> to the constructors signature to get c# to call the inherited constructor.</p>
<p>If you need to pass parameters through to the inherited call, <strong>use :base(param1, param2)</strong></p>
<p>As soon as you add a descendant that overrides the parameter list for a classes constructor, any other descendant classes will have to have a constructor implementation, similar to the Derived class below, to let the compiler know which of the inherited constructors needs calling when the descendant class is created. Otherwise a “No overload for method ‘x’ takes ‘0′ arguments” error may occur</p>
]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/how-to-override-constructors-and-pass-extra-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a bit-based enumeration</title>
		<link>http://lummie.co.uk/how-to-create-a-bit-based-enumeration/</link>
		<comments>http://lummie.co.uk/how-to-create-a-bit-based-enumeration/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:37:52 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=412</guid>
		<description><![CDATA[If you want to create an enumeration that acts like a set, where the value of the enumeration can be a combination of any of the members of the enumeration then you C# allows you to do this using the &#8230; <a href="http://lummie.co.uk/how-to-create-a-bit-based-enumeration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to create an enumeration that acts like a set, where the value of the enumeration can be a combination of any of the members of the enumeration then you C# allows you to do this using the FlagsAttribute.</p>
<p>Simply add the attribute to the start of the enumeration and the enumeration values will be treated as bit flags instead.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>FlagsAttribute<span style="color: #008000;">&#93;</span>
<span style="color: #6666cc; font-weight: bold;">enum</span> Colors <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">short</span>
<span style="color: #008000;">&#123;</span>
	None <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
	Red <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
	Green <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
	Blue <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span>,
	White <span style="color: #008000;">=</span> <span style="color: #FF0000;">7</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></pre></div></div>

<p>You can use bitwise operators Not, And, Or and XOR on the enumeration.</p>
<p>e.g. to see if an enumeration value is set</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span> Colors <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> Red <span style="color: #008000;">==</span> Red<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// do something</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Note that the not (!) does not work on bitwise operations so the complement(~) operator is required.</p>
<p>So to remove a the red and green flag from the set…</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Colors <span style="color: #008000;">=</span> Colors <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> ~<span style="color: #008000;">&#40;</span>Red <span style="color: #008000;">|</span> Green<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/how-to-create-a-bit-based-enumeration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Exceptions and Serialization.</title>
		<link>http://lummie.co.uk/custom-exceptions-and-serialization/</link>
		<comments>http://lummie.co.uk/custom-exceptions-and-serialization/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:36:52 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=410</guid>
		<description><![CDATA[Microsoft state that if you want to raise custom exceptions in your application then you should derive them from the ApplicationException class and not the Exception class. ApplicationException is thrown by a user program, not by the common language runtime. &#8230; <a href="http://lummie.co.uk/custom-exceptions-and-serialization/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Microsoft state that if you want to raise custom exceptions in your application then you should derive them from the ApplicationException class and not the Exception class.</p>
<p>ApplicationException is thrown by a user program, not by the common language runtime. If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception, but does not add new functionality. This exception is provided as means to differentiate between exceptions defined by applications versus exceptions defined by the system.</p>
<p>However, the blog entry by Microsoft’s Brad Adams states that ApplicationException should not be used !</p>
<p>I found that descending from Exception, at least gives a nice error message detailing the exception that was raised as opposed to ApplicationExceptiosn, “Application Error ocurred” message.</p>
<p>So how do we serialize a custom exception class ?</p>
<p>Step 1) Add the Serializable attribute to the exception</p>
<p>Step 2) Provide a contructor that takes the serialization information and context e.g. MyException(SerializationInfo info, StreamingContext context)<br />
Step 3) If you have a constructor that passes state information to the exception to be included in the data collection ensure this is copied from the exception object to the info in the serialization constructor (step2)</p>
<p>e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyException <span style="color: #008000;">:</span> Exception
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> MyException<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> sessionId<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SessionID&quot;</span>, sessionId<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> MyException<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span>info, context<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		info<span style="color: #008000;">.</span><span style="color: #0000FF;">AddValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SessionID&quot;</span>,Data<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;SessionID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> GetObjectData<span style="color: #008000;">&#40;</span>SerializationInfo info, StreamingContext context<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetObjectData</span><span style="color: #008000;">&#40;</span>info, context<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/custom-exceptions-and-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nullable Types</title>
		<link>http://lummie.co.uk/nullable-types/</link>
		<comments>http://lummie.co.uk/nullable-types/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:36:07 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=408</guid>
		<description><![CDATA[In C# and .net you can define a variable of the standard values types to be nullable as well. This is extremely useful in circumstances when you want to check if a varaible has been intialized correctly. For example, if &#8230; <a href="http://lummie.co.uk/nullable-types/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In C# and .net you can define a variable of the standard values types to be nullable as well. This is extremely useful in circumstances when you want to check if a varaible has been intialized correctly.</p>
<p>For example, if you have a class that represents a user which has an integer user id and it is not initialized in the constructor. Rather than having the user id intitialize to 0 (zero) (which would be the default for an integer) as the User id 0 may well be a valid user’s id. the type can be defined as a nullable integer using int? UserID and will default to null instead.</p>
<p>Examples of nullable declarations</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">?</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">?</span> d1 <span style="color: #008000;">=</span> <span style="color: #FF0000;">3.14</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">?</span> flag <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">char</span><span style="color: #008000;">?</span> letter <span style="color: #008000;">=</span> <span style="color: #666666;">'a'</span><span style="color: #008000;">;</span>
<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">?</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> arr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">?</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">10</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/nullable-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hex String to byte array converter</title>
		<link>http://lummie.co.uk/hex-string-to-byte-array-converter/</link>
		<comments>http://lummie.co.uk/hex-string-to-byte-array-converter/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 13:34:55 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=406</guid>
		<description><![CDATA[The following simple static class will take a string of Hexdecimal characters and convert it to a byte array. static class HexStringConverter &#123; public static byte&#91;&#93; ToByteArray&#40;String HexString&#41; &#123; int NumberChars = HexString.Length; byte&#91;&#93; bytes = new byte&#91;NumberChars / 2&#93;; &#8230; <a href="http://lummie.co.uk/hex-string-to-byte-array-converter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The following simple static class will take a string of Hexdecimal characters and convert it to a byte array.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> HexStringConverter
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> ToByteArray<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> HexString<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">int</span> NumberChars <span style="color: #008000;">=</span> HexString<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
            <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> bytes <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>NumberChars <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> NumberChars<span style="color: #008000;">;</span> i <span style="color: #008000;">+=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                bytes<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToByte</span><span style="color: #008000;">&#40;</span>HexString<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span>i, <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">16</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> bytes<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>or an alternative supplied by Peter Speybrouck:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> ToByteArray<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> HexString<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> NumberChars<span style="color: #008000;">;</span> i <span style="color: #008000;">+=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">try</span>
        <span style="color: #008000;">&#123;</span>
            bytes<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToByte</span><span style="color: #008000;">&#40;</span>Hex<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span>i, <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">16</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">catch</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//failed to convert these 2 chars, they may contain illegal charracters</span>
            bytes<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> bytes<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>* fixes uneven number of hex characters by adding a zero in front of the string<br />
* handles illegal characters gracefully</p>
<p>or</p>
<p>ASKORO: December 24, 2009 at 10:59 am</p>
<p>How about this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sVal<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">%</span> <span style="color: #FF0000;">2</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> ArgumentException<span style="color: #008000;">&#40;</span>“Hex <span style="color: #6666cc; font-weight: bold;">string</span> <span style="color: #008000;">is</span> of odd length”<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Regex re <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #008000;">&#40;</span>@”<span style="color: #008000;">&#91;</span><span style="color: #008000;">^</span><span style="color: #FF0000;">0</span><span style="color: #008000;">-</span>9A<span style="color: #008000;">-</span>Fa<span style="color: #008000;">-</span>f<span style="color: #008000;">&#93;</span>“<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>re<span style="color: #008000;">.</span><span style="color: #0000FF;">IsMatch</span><span style="color: #008000;">&#40;</span>sVal<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> ArgumentException<span style="color: #008000;">&#40;</span>“Hex <span style="color: #6666cc; font-weight: bold;">string</span> contains invalid characters”<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> Encoding<span style="color: #008000;">.</span><span style="color: #0000FF;">ASCII</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>sVal<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/hex-string-to-byte-array-converter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create an Expandable Object Converter that will drop down a list of Class Types</title>
		<link>http://lummie.co.uk/how-to-create-an-expandable-object-converter-that-will-drop-down-a-list-of-class-types/</link>
		<comments>http://lummie.co.uk/how-to-create-an-expandable-object-converter-that-will-drop-down-a-list-of-class-types/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 12:42:10 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=404</guid>
		<description><![CDATA[This article provides an example of a TypeConverter which, when displayed in a Property Grid, will allow the user to select an class type from the drop down list. When an item is selected, it creates and instance of that &#8230; <a href="http://lummie.co.uk/how-to-create-an-expandable-object-converter-that-will-drop-down-a-list-of-class-types/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This article provides an example of a TypeConverter which, when displayed in a Property Grid, will allow the user to select an class type from the drop down list. When an item is selected, it creates and instance of that class type. This can be used, for example, if you had a property of type Shape, and wanted to allow the user to choose a shape to assign to that property, e.g. Circle, Rectangle, etc. The property has a type of the base class Shape, but ends up with the appropriate instance of a descendant class. In the following example, I have a abstract base class of GridStyleBorder which is a property on an object.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span>Category<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Appearance&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #008000;">&#91;</span>Browsable<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> 
<span style="color: #008000;">&#91;</span>TypeConverter<span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>GridBorderTypeConverter<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> 
<span style="color: #008000;">&#91;</span>RefreshProperties<span style="color: #008000;">&#40;</span>RefreshProperties<span style="color: #008000;">.</span><span style="color: #0000FF;">All</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> 
<span style="color: #008000;">&#91;</span>Description<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Change the Border Style&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> 
<span style="color: #008000;">&#91;</span>DesignerSerializationVisibility<span style="color: #008000;">&#40;</span>DesignerSerializationVisibility<span style="color: #008000;">.</span><span style="color: #0000FF;">Content</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span> 
<span style="color: #0600FF; font-weight: bold;">public</span> GridStyleBorder Border <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span>  <span style="color: #0600FF; font-weight: bold;">return</span> _border<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> set <span style="color: #008000;">&#123;</span> _border <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Notice the TypeConvert is set to GridBorderTypeConverter this is a new TypeConvert descended from ExpandableObjectConverter. The code is below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Drawing.Drawing2D</span><span style="color: #008000;">;</span>
 <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Reflection</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">namespace</span> SomeAssemby <span style="color: #008000;">&#123;</span>
     <span style="color: #008080; font-style: italic;">/// Provides the type converter that displays a list of types. </span>
     <span style="color: #008080; font-style: italic;">/// When the user selects an item from the list, an instance of that type is created.</span>
     <span style="color: #008080; font-style: italic;">/// Note : requires customization to work with other property types. (see comments)</span>
     <span style="color: #008080; font-style: italic;">/// </span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">class</span> GridBrushTypeConverter <span style="color: #008000;">:</span> ExpandableObjectConverter
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// set the next array to be an array of types you wish to display in the drop down</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Type<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> TypesToDisplay <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Type<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> 
            <span style="color: #008000;">&#123;</span> 
                <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>SolidBrush<span style="color: #008000;">&#41;</span>, 
                <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>LinearGradientBrush<span style="color: #008000;">&#41;</span> 
            <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">// Change the modify region to If Else tests for each type you support and return appropriate instances of the types.</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">object</span> ConvertFrom<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ITypeDescriptorContext</span> context, <span style="color: #000000;">System.<span style="color: #0000FF;">Globalization</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">CultureInfo</span> culture, <span style="color: #6666cc; font-weight: bold;">object</span> value<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>value<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> fullClassName <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span>value<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080;">#region —- need to modify this section ———————</span>
                <span style="color: #008080; font-style: italic;">// check the full classname and return a new instance of that class for each of the types you support</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>fullClassName <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>LinearGradientBrush<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FullName</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> LinearGradientBrush<span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>, <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">100</span><span style="color: #008000;">&#41;</span>,SystemColors<span style="color: #008000;">.</span><span style="color: #0000FF;">Control</span>, SystemColors<span style="color: #008000;">.</span><span style="color: #0000FF;">ControlDark</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">else</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> SolidBrush<span style="color: #008000;">&#40;</span>SystemColors<span style="color: #008000;">.</span><span style="color: #0000FF;">Control</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080;">#endregion</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertFrom</span><span style="color: #008000;">&#40;</span>context, culture, value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region —- No need to change this code —————————————</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> ArrayList TypesToDisplayArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArrayList<span style="color: #008000;">&#40;</span>TypesToDisplay<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> GetStandardValuesSupported<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ITypeDescriptorContext</span> context<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">TypeConverter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StandardValuesCollection</span> GetStandardValues<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ITypeDescriptorContext</span> context<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> StandardValuesCollection<span style="color: #008000;">&#40;</span>TypesToDisplayArray<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CanConvertFrom<span style="color: #008000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">ITypeDescriptorContext</span> context, <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Type</span> sourceType<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sourceType <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">else</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CanConvertFrom</span><span style="color: #008000;">&#40;</span>context, sourceType<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/how-to-create-an-expandable-object-converter-that-will-drop-down-a-list-of-class-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use an inline delegate with the Find method on collections</title>
		<link>http://lummie.co.uk/how-to-use-an-inline-delegate-with-the-find-method-on-collections/</link>
		<comments>http://lummie.co.uk/how-to-use-an-inline-delegate-with-the-find-method-on-collections/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 12:40:15 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=402</guid>
		<description><![CDATA[C# provides a very powerful and concise method of locating items in collections. The find Method on collections and generic lists (and other collection type classes) take a predicate as the parameter. To the beginner programmer the power of this &#8230; <a href="http://lummie.co.uk/how-to-use-an-inline-delegate-with-the-find-method-on-collections/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>C# provides a very powerful and concise method of locating items in collections.  The find Method on collections and generic lists (and other collection type classes) take a predicate as the parameter.  To the beginner programmer the power of this parameter is not obvious.</p>
<p>Lets take a simple collection of objects, MyClass defined as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #6666cc; font-weight: bold;">class</span> MyClass
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Id<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> Name<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p> and an associated collection, in this cas a simple generic list.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #6666cc; font-weight: bold;">class</span> MyClassCollection <span style="color: #008000;">:</span> List<span style="color: #008000;">&lt;</span>MyClass<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">...</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Implementing a couple of methods to Find by Id or name is really simple with the Find method.  We create an inline delegate that returns a boolean true of false if a match occurs. e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> MyClass FindByID<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Find</span><span style="color: #008000;">&#40;</span>
            <span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span>MyClass itemInCollection<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>itemInCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>The FindByID method returns an instance of MYClass that the Find method locates.</p>
<p>The FindMethod takes and inline delegate that expects the current instance that the find method is looking at to be passed in (itemInCollection).</p>
<p>As the delegate is inline, it can reference the id parameter passed into the FindByID method and this can be used in the comparison.</p>
<p>An alternative to method of implementation is to pass as the predicate, a equality method that is defiend on the collection class, but this would mean that the value you are trying to find would have to be set as public field on the collecttion class, and therefore mutliple threads could not search the collection at the same time.</p>
<p>Below is an example of the class with a FindByName delegate as well.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #6666cc; font-weight: bold;">class</span> MyClassCollection <span style="color: #008000;">:</span> List<span style="color: #008000;">&lt;</span>MyClass<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> MyClass FindByID<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> id<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Find</span><span style="color: #008000;">&#40;</span>
                <span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span>MyClass itemInCollection<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>itemInCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> MyClass FindByID<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> name<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Find</span><span style="color: #008000;">&#40;</span>
                <span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span>MyClass itemInCollection<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>itemInCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> name<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/how-to-use-an-inline-delegate-with-the-find-method-on-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a string of Repeating Characters</title>
		<link>http://lummie.co.uk/create-a-string-of-repeating-characters/</link>
		<comments>http://lummie.co.uk/create-a-string-of-repeating-characters/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 12:36:53 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://lummie.co.uk/?p=400</guid>
		<description><![CDATA[Creating a string of repeating characters is really simple in c#, however it is not in the obvious place you would look. First I tried the String class, hoping there would be a static like String.RepeatString, and even looked in &#8230; <a href="http://lummie.co.uk/create-a-string-of-repeating-characters/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Creating a string of repeating characters is really simple in c#, however it is not in the obvious place you would look.  First I tried the String class, hoping there would be a static like String.RepeatString, and even looked in the StringBuilder class.  Eventually found it in a very logical place when you think about it, the String classes constructor.<br />
String (Char, Int32)<br />
So to create a repeating string simply use</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">String</span> myString <span style="color: #008000;">=</span> newString<span style="color: #008000;">&#40;</span><span style="color: #666666;">'x'</span>, <span style="color: #FF0000;">12</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>which will create a string of x’s 12 characters long.</p>
]]></content:encoded>
			<wfw:commentRss>http://lummie.co.uk/create-a-string-of-repeating-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

