<?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>Infinity &#187; C#</title>
	<atom:link href="http://blog.cyragon.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cyragon.com</link>
	<description>where it all begins</description>
	<lastBuildDate>Fri, 11 Feb 2011 20:26:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>C# vs Java: casting objects and calling members</title>
		<link>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/</link>
		<comments>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 20:24:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.cyragon.com/?p=210</guid>
		<description><![CDATA[Given these two functionally identical code samples in c# and java, what is the output? C#: public class A { &#160;&#160;public String Method() &#160;&#160;{ &#160;&#160;&#160;&#160;return &#34;this is A&#34;; &#160;&#160;} } public class B : A { &#160;&#160;public String Method() &#160;&#160;{ &#160;&#160;&#160;&#160;return &#34;this is B&#34;; &#160;&#160;} } A thisA = new B(); thisA.Method(); Java: public class [...]]]></description>
			<content:encoded><![CDATA[<p>Given these two functionally identical code samples in c# and java, what is the output?</p>
<p>C#:<br />
<pre><code>public class A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is A&quot;;
&nbsp;&nbsp;}
}

public class B : A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is B&quot;;
&nbsp;&nbsp;}
}

A thisA = new B();

thisA.Method();</code></pre></p>
<p>Java:<br />
<pre><code>public class A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is A&quot;;
&nbsp;&nbsp;}
}

public class B extends A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is B&quot;;
&nbsp;&nbsp;}
}

A thisA = new B();

thisA.Method();</code></pre></p>
<p>What does thisA.Method() return? </p>
<p>It turns out that there are two different answers to this. In .NET/C# it returns from A (&#8220;this is A&#8221;). In Java, it returns from B (&#8220;this is B&#8221;). </p>
<p>So far it appears that this is a type issue; new B() must be getting cast back to A in C#. Looking for some documentation on this specifically. Links anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using LINQ to process RegEx matches</title>
		<link>http://blog.cyragon.com/2008/12/using-linq-to-process-regex-matches/</link>
		<comments>http://blog.cyragon.com/2008/12/using-linq-to-process-regex-matches/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 22:23:43 +0000</pubDate>
		<dc:creator>Ben Farmer</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://blog.cyragon.com/?p=56</guid>
		<description><![CDATA[Today I used LINQ to help implement a cleaner solution to a problem I was trying to solve. It&#8217;s really just some syntactic sugar and a chance to use a buzzword (LINQ). My simple data class: ?Download download.txt1 2 3 4 5 public class ReturnRecord &#123; public String FieldKey; public String FieldValue; &#125; Basically, I [...]]]></description>
			<content:encoded><![CDATA[<p>Today I used LINQ to help implement a cleaner solution to a problem I was trying to solve. It&#8217;s really just some syntactic sugar and a chance to use a buzzword (LINQ).</p>
<p>My simple data class:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.cyragon.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=56&amp;download=download.txt">download.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p566"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p56code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ReturnRecord
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> FieldKey<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">String</span> FieldValue<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Basically, I needed to return an array with the key/value pairs found in a text document (of type ReturnRecord[]). RegEx was my obvious choice for parsing the text and finding the key value pairs. The keys and values will be decorated with #&#8217;s in the document.<br />
Sample text:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.cyragon.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=56&amp;download=download.txt">download.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p567"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p56code7"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">String</span> text <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Blah blah #key#value# blah blah.&quot;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Here is my RegEx setup:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.cyragon.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=56&amp;download=download.txt">download.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p568"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p56code8"><pre class="csharp" style="font-family:monospace;">Regex regex <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;#(.+?)#(.+?)#&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
MatchCollection keyvalues <span style="color: #008000;">=</span> regex<span style="color: #008000;">.</span><span style="color: #0000FF;">Matches</span><span style="color: #008000;">&#40;</span>text<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Now I can use a nifty LINQ query to create the array for me without having to write the usual for-loop plumbing. As you can see, LINQ creates the objects and initializes them for me in a single query.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.cyragon.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=56&amp;download=download.txt">download.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p569"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p56code9"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span>returnrow<span style="color: #008000;">&gt;</span> results<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>keyvalues<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
results <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> Match m <span style="color: #0600FF; font-weight: bold;">in</span> keyvalues
<span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ReturnRow
   <span style="color: #008000;">&#123;</span> FieldKey <span style="color: #008000;">=</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Groups</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, 
     FieldValue <span style="color: #008000;">=</span> m<span style="color: #008000;">.</span><span style="color: #0000FF;">Groups</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">&#125;</span>
     <span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&lt;/</span>returnrow<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>All that&#8217;s left is to return</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://blog.cyragon.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=56&amp;download=download.txt">download.txt</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5610"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p56code10"><pre class="csharp" style="font-family:monospace;">results<span style="color: #008000;">.</span><span style="color: #0000FF;">ToArray</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></pre></td></tr></table></div>

<p> and I&#8217;m done. It&#8217;s that much less for me to maintain.</p>
<p>MSDN has some examples as well <a href="http://msdn.microsoft.com/en-us/library/bb882639.aspx">http://msdn.microsoft.com/en-us/library/bb882639.aspx</a> or, check out this post <a href="http://schotime.net/index.php/2008/03/10/linq-and-regular-expressions/">http://schotime.net/index.php/2008/03/10/linq-and-regular-expressions/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cyragon.com/2008/12/using-linq-to-process-regex-matches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
