<?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/tag/c/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.1</generator>
		<item>
		<title>XCode: The Starting Curly Brace</title>
		<link>http://scyanide.com/2010/02/xcode-the-starting-curly-brace/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xcode-the-starting-curly-brace</link>
		<comments>http://scyanide.com/2010/02/xcode-the-starting-curly-brace/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 05:09:32 +0000</pubDate>
		<dc:creator>Scyanide</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[newline]]></category>
		<category><![CDATA[obj]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[same line]]></category>
		<category><![CDATA[starting curly brace]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://scyanide.com/?p=410</guid>
		<description><![CDATA[As I dive deeper into the world of programming for Apple hardware I bring along with me past practices or habits that I must change in order to fit into the Objective-C world. It has been years since I last touched C/C++ and coming from a world of .NET and C#, my first impressions of [...] [...]]]></description>
			<content:encoded><![CDATA[<p>As I dive deeper into the world of programming for Apple hardware I bring along with me past practices or habits that I must change in order to fit into the Objective-C world. It has been years since I last touched C/C++ and coming from a world of .NET and C#, my first impressions of XCode and Objective-C was basically taking a few steps backwards.</p>
<p>I couldn&#8217;t have been more wrong&#8230;</p>
<p><span id="more-410"></span></p>
<p>I see the power of what this new world has to offer and thus as I continue my journey I am finding myself taking new approaches to situations and even finding that some old habits I just flat out prefer to hold on to. Today, I&#8217;m talking about the placement of the starting curly brace.</p>
<p>Now, it seems to be common place in the C/C++ world where the starting curly brace is on the same line as the starting block of code. For example&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">void</span> someFunction<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">//code...</span>
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>In the C# world it seems to be common place to place the curly brace on a new line. For example&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> someMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">//code...</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>There are various arguments on why each one is better. Commonly I hear that the first method is better because it doesn&#8217;t have wasted space which results in less scrolling. While on the flip side, I commonly hear that by placing the curly brace on a newline it makes for easier readability. In the end, it really only comes down to personal preference as the placement has zero effect on the result of the executed code.</p>
<p>Personally, I prefer and have always preferred placing the curly brace on a new line. Why is this? Well, it is what I got used to while using Visual Studio for so long. It has occurred to me that the big named IDE&#8217;s out there seem to have a bit of a role, or rather influence, in how the community adopts the typical way a programming language is written out. With the exception, of course, of those individuals who take the time to rummage through the IDE&#8217;s preferences and change auto features to their liking.</p>
<p>Which is where my recent adventure comes into the story. While working in XCode I noticed the predicting text feature (amazing by the way, really wish Visual Studio had this) would always place the starting curly brace on the same line as my starting block of code. After a short period I stopped relying on the predicting text feature and just wrote everything out so that I would have to interrupt my typing flow to move the curly brace.</p>
<p><a href="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.47.56-PM.png"><img class="aligncenter size-full wp-image-417" title="Screen shot 2010-02-23 at 12.47.56 PM" src="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.47.56-PM.png" alt="" width="328" height="216" /></a></p>
<p>The image above shows XCode&#8217;s auto predicting magic (seriously, I have no clue what it is actually called) on an &#8216;if&#8217; statement. Getting a little tired of having the starting curly brace on the same line I went through XCode&#8217;s preferences to change it but was given a little shock. There are no options to change this from the IDE.</p>
<p>I was a little disappointed but had not given up just yet as I did recall that the Apple world revolves around plist configuration files and held hope that maybe there was still a way.</p>
<p style="text-align: center;"><a href="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.47.02-PM.png"><img class="aligncenter size-medium wp-image-416" title="Screen shot 2010-02-23 at 12.47.02 PM" src="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.47.02-PM-300x203.png" alt="" width="300" height="203" /></a>Home: Library-&gt;Preferences-&gt;com.apple.Xcode.plist</p>
<p style="text-align: left;">I had found the plist file in the above location and as I opened it and looked through I couldn&#8217;t find any settings that would allow me to make the change I wanted. Looking around online I found what I was looking for, I needed the following inside this plist:</p>
<p style="text-align: left;">XCCodeSenseFormattingOptions as a dictionary along with BlockSeparator inside the newly created dictionary with the string value of a newline character.</p>
<p style="text-align: left;">I tried doing this manually through the plist editor that comes with the OS but I couldn&#8217;t get it to work correctly and so looking around online I found out how to manually edit plists from the terminal:</p>
<p style="text-align: left;"><strong>defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator &#8220;\\n&#8221;</strong></p>
<p style="text-align: left;">By typing in the above line I had achieved my goal:</p>
<p style="text-align: left;"><a href="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.55.54-PM.png"><img class="aligncenter size-full wp-image-419" title="Screen shot 2010-02-23 at 12.55.54 PM" src="http://scyanide.com/wp-content/uploads/2010/02/Screen-shot-2010-02-23-at-12.55.54-PM.png" alt="" width="329" height="188" /></a></p>
<p style="text-align: left;">Now when I type such statements as &#8216;if&#8217; this is what automatically shows up in XCode.</p>
<p style="text-align: left;">The issues I had doing it manually through a plist editor was that I needed that hidden newline character &#8216;\n&#8217; but typing it out manually only cause actual characters to be printed: For example&#8230;</p>
<p style="text-align: left;">if (condition)\n{</p>
<p style="text-align: left;">statements</p>
<p style="text-align: left;">}</p>
<p style="text-align: left;">So, with that if any of you, like me, prefer to have their curly braces start on a newline in XCode. Just the bolded line above in a terminal and you should be all set. Happy Coding!</p>
<p style="text-align: left;">NOTE: If you copy and paste the bolded line be careful of the quotes. Might just want to type that part in by hand. It has been my past experiences that showed copying lines of code with single and double quotes from a website does not always go over too well everytime.</p>
]]></content:encoded>
			<wfw:commentRss>http://scyanide.com/2010/02/xcode-the-starting-curly-brace/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<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>

