<?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>Scyanide Chatter &#187; C#</title>
	<atom:link href="http://scyanide.com/category/my-thoughts/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://scyanide.com</link>
	<description>My life, interests, and random babble...</description>
	<lastBuildDate>Tue, 17 Jan 2012 03:43:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>C# and the readonly keyword</title>
		<link>http://scyanide.com/2009/09/c-and-the-readonly-keyword/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-and-the-readonly-keyword</link>
		<comments>http://scyanide.com/2009/09/c-and-the-readonly-keyword/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 19:55:32 +0000</pubDate>
		<dc:creator>Scyanide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[declaration]]></category>
		<category><![CDATA[initialize]]></category>
		<category><![CDATA[readonly]]></category>

		<guid isPermaLink="false">http://scyanide.com/?p=376</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2026</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2026</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2398</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3351</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3374</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3374</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3415</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3467</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3467</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3612</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3612</b><br />
I came across something interesting today and thought I&#8217;d share this small bit of information to the world. While this made me scratch my head for a second or two it really does make sense. In C#, and I assume VB.NET as well, we have the keyword readonly which allows one to initialize a read [...] [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2026</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2026</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2398</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3351</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3374</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3374</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3415</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3467</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3467</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3612</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/pvinson/scyanide.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3612</b><br />
<p>I came across something interesting today and thought I&#8217;d share this small bit of information to the world. While this made me scratch my head for a second or two it really does make sense. In C#, and I assume VB.NET as well, we have the keyword <em>readonly</em> which allows one to initialize a read only variable during declaration or within a constructor. I recently had the situation where I needed to use a <em>readonly</em> but couldn&#8217;t figure out the best area to place it, either in my parent class or in each child class created. Being one who believes less code is better I leaned towards just throwing it in my parent class. It turns out though, that a read only variable can ONLY be initialized during its declaration or in the class the read only variable resides in and children classes WILL NOT be allowed to initialize the variable.</p>
<p><span id="more-376"></span></p>
<p>Here is a quick and dirty code example of what I&#8217;m talking about&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;">  public class ClassA
  <span class="br0">&#123;</span>
    protected readonly String stringA;
&nbsp;
    public ClassA<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span>
  <span class="br0">&#125;</span>
&nbsp;
  public class ClassB : ClassA
  <span class="br0">&#123;</span>
    public ClassB<span class="br0">&#40;</span>String value<span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
      stringA = value; // ERROR: A readonly field cannot be assigned to <span class="br0">&#40;</span>except in a constructor or a variable initializer<span class="br0">&#41;</span>
    <span class="br0">&#125;</span>
  <span class="br0">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scyanide.com/2009/09/c-and-the-readonly-keyword/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# Gotcha or /Facepalm moment?</title>
		<link>http://scyanide.com/2009/07/c-gotcha-or-facepalm-moment/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-gotcha-or-facepalm-moment</link>
		<comments>http://scyanide.com/2009/07/c-gotcha-or-facepalm-moment/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 14:36:30 +0000</pubDate>
		<dc:creator>Scyanide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[stack overflow]]></category>

		<guid isPermaLink="false">http://scyanide.com/?p=350</guid>
		<description><![CDATA[So I was playing around with a little idea and while putting together a simple class, very hastily I might add, I accidentally did something that caused a StackOverflowException to be thrown. 1 2 3 4 5 private Int32 someValue; public Int32 SomeValue &#123; get &#123; return SomeValue; &#125; &#125; This is a very simple [...] [...]]]></description>
			<content:encoded><![CDATA[<p>So I was playing around with a little idea and while putting together a simple class, very hastily I might add, I accidentally did something that caused a <a href="http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx" target="_blank">StackOverflowException</a> to be thrown.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">  <span style="color: #0600FF; font-weight: bold;">private</span> Int32 someValue<span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> Int32 SomeValue
  <span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> SomeValue<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-350"></span></p>
<p>This is a very simple version of a Property in C# but can you see what is wrong with this bit of code? Take a look at the returned variable name, see how it starts with a capital &#8216;S&#8217;? This code actually does cause a StackOverflowException. Obviously, you want to use &#8216;someValue&#8217; and not &#8216;SomeValue&#8217; in your get and set methods. I made this mistake because I was in a rush and using Visual Studio&#8217;s little intellisense helper I accidentally selected my newly created Property over the actual variable I needed.</p>
<p>On a side note, I <em>really</em> need to find a good code colorizer/formatter plugin for WordPress. Does anyone have any good suggestions?</p>
]]></content:encoded>
			<wfw:commentRss>http://scyanide.com/2009/07/c-gotcha-or-facepalm-moment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use C# To Fill Out Web Forms</title>
		<link>http://scyanide.com/2009/07/use-c-sharp-to-fill-out-web-forms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=use-c-sharp-to-fill-out-web-forms</link>
		<comments>http://scyanide.com/2009/07/use-c-sharp-to-fill-out-web-forms/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 15:59:34 +0000</pubDate>
		<dc:creator>Scyanide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[HtmlDocument]]></category>
		<category><![CDATA[HtmlElement]]></category>
		<category><![CDATA[InvokeMember]]></category>
		<category><![CDATA[SetAttribute]]></category>
		<category><![CDATA[WebBrowser]]></category>

		<guid isPermaLink="false">http://scyanide.com/?p=346</guid>
		<description><![CDATA[I figured I&#8217;d give out a quick tip that I had to recently do in C#. A friend had asked me how to automatically fill out a web form and submit it so that he could grab the html of the results page. Luckily, it is VERY simple in C# and I assume it is [...] [...]]]></description>
			<content:encoded><![CDATA[<p>I figured I&#8217;d give out a quick tip that I had to recently do in C#. A friend had asked me how to automatically fill out a web form and submit it so that he could grab the html of the results page. Luckily, it is VERY simple in C# and I assume it is just as easy in VB.NET too&#8230;</p>
<blockquote><p>HtmlDocument document = browser.Document;<br />
HtmlElement inputValue = document.GetElementById(&#8220;ctl00_ContentPlaceHolder1_txtNAICS&#8221;);<br />
element.SetAttribute(&#8220;value&#8221;, &#8220;334511&#8243;);<br />
HtmlElement submitButton = document.GetElementById(&#8220;ctl00_ContentPlaceHolder1_btnSearch2&#8243;);<br />
submitButton.InvokeMember(&#8220;click&#8221;);</p></blockquote>
<p> <span id="more-346"></span></p>
<p>What you do is basically grab your HtmlDocument from the browser control AFTER the page has been fully loaded. From here you have some choices, if you know the ID of the elements you want and if it is not a lot of elements you can grab each element and store them into separate HtmlElement objects. If you want to fill out ALL input elements then you can use GetElementsByTagName(&#8220;input&#8221;) in place of GetElementByID(). The tag name method returns an HtmlElementCollection which you can just throw that line into a foreach loop for every HtmlElement.</p>
<p>Once you have your HtmlElement object that contains the correct input which you want to fill in, you can then call SetAttribute(&#8220;value&#8221;, &#8220;some value&#8221;). All you would need to do is change &#8220;some value&#8221; to whatever value you&#8217;re filling in.</p>
<p>Later on, you&#8217;ll need to submit the form. I&#8217;m not sure if there are various ways of going about this but I found that just by finding the submit element by its ID and invoking &#8220;click&#8221; seems to work just fine.</p>
<p>I realize this is not very detailed but as I write more C# examples and such I&#8217;ll get into a more detailed practice.</p>
]]></content:encoded>
			<wfw:commentRss>http://scyanide.com/2009/07/use-c-sharp-to-fill-out-web-forms/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

