<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: If Then Else Shorthand in C#</title>
	<atom:link href="http://dustyreagan.com/if-then-else-shorthand-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://dustyreagan.com/if-then-else-shorthand-in-c/</link>
	<description>On Technology &#38; Entrepreneurship</description>
	<lastBuildDate>Thu, 10 May 2012 21:14:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Mike K</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-2815</link>
		<dc:creator>Mike K</dc:creator>
		<pubDate>Wed, 15 Feb 2012 16:23:49 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-2815</guid>
		<description>Sashi does have a point. In the following scenario the Thing1 property is nullable, and therefore does allow a null value. The tradition if/else works here but the shorthand version will give you an error.

public class Stuff
    {
        public Stuff( DataRow dr )
        {
            if( Convert.IsDBNull( dr[&quot;thing1&quot;] ) )
            {
                Thing1 = null;
            }
            else
            {
                Thing1 = Convert.ToInt32( dr[&quot;thing1&quot;] );
            }

            Thing2 = Convert.IsDBNull( dr[&quot;thing2&quot;] ) ? null : dr[&quot;thing2&quot;].ToString();
        }

        int? Thing1 { get; set; }
        string Thing2 { get; set; }
    }</description>
		<content:encoded><![CDATA[<p>Sashi does have a point. In the following scenario the Thing1 property is nullable, and therefore does allow a null value. The tradition if/else works here but the shorthand version will give you an error.</p>
<p>public class Stuff<br />
    {<br />
        public Stuff( DataRow dr )<br />
        {<br />
            if( Convert.IsDBNull( dr["thing1"] ) )<br />
            {<br />
                Thing1 = null;<br />
            }<br />
            else<br />
            {<br />
                Thing1 = Convert.ToInt32( dr["thing1"] );<br />
            }</p>
<p>            Thing2 = Convert.IsDBNull( dr["thing2"] ) ? null : dr["thing2"].ToString();<br />
        }</p>
<p>        int? Thing1 { get; set; }<br />
        string Thing2 { get; set; }<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: G</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-2687</link>
		<dc:creator>G</dc:creator>
		<pubDate>Tue, 13 Sep 2011 16:41:45 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-2687</guid>
		<description>The parenthesis doesn&#039;t actually make any difference; it should still work with them on.</description>
		<content:encoded><![CDATA[<p>The parenthesis doesn&#8217;t actually make any difference; it should still work with them on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bobhanzo</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-2565</link>
		<dc:creator>Bobhanzo</dc:creator>
		<pubDate>Thu, 28 Jul 2011 07:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-2565</guid>
		<description>Edit: 
I mean it&#039;s:
Data[2] = min &gt; 0 ? 0×00 : oxo1;</description>
		<content:encoded><![CDATA[<p>Edit:<br />
I mean it&#8217;s:<br />
Data[2] = min &gt; 0 ? 0×00 : oxo1;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bobhanzo</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-2564</link>
		<dc:creator>Bobhanzo</dc:creator>
		<pubDate>Thu, 28 Jul 2011 07:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-2564</guid>
		<description>Im sure you found your answer already but for the next one who gets this problem:

Dont use the ( )

Just type:
Data[2] = (min &gt; 0) ? 0×00 : oxo1;</description>
		<content:encoded><![CDATA[<p>Im sure you found your answer already but for the next one who gets this problem:</p>
<p>Dont use the ( )</p>
<p>Just type:<br />
Data[2] = (min &gt; 0) ? 0×00 : oxo1;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ruben</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-2512</link>
		<dc:creator>Ruben</dc:creator>
		<pubDate>Thu, 12 May 2011 11:51:01 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-2512</guid>
		<description>How can I write this shorter?
            if (min &gt; 0)
            {
                Data[2] = 0x00;
            }
            else { 
                Data[2] = 0x01;
            }
I Tried
Data[2] = (min &gt; 0) ? 0x00 : oxo1;

The Data array is Byte and min is integer. It should not be a problem. but in the short form it is not working.
Any ideas?</description>
		<content:encoded><![CDATA[<p>How can I write this shorter?<br />
            if (min &gt; 0)<br />
            {<br />
                Data[2] = 0&#215;00;<br />
            }<br />
            else {<br />
                Data[2] = 0&#215;01;<br />
            }<br />
I Tried<br />
Data[2] = (min &gt; 0) ? 0&#215;00 : oxo1;</p>
<p>The Data array is Byte and min is integer. It should not be a problem. but in the short form it is not working.<br />
Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dusty Reagan</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-556</link>
		<dc:creator>Dusty Reagan</dc:creator>
		<pubDate>Mon, 04 Oct 2010 00:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-556</guid>
		<description>Thanks for the clarification Tyler. I fixed the typo. :)</description>
		<content:encoded><![CDATA[<p>Thanks for the clarification Tyler. I fixed the typo. <img src='http://dustyreagan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tyler Cash</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-555</link>
		<dc:creator>Tyler Cash</dc:creator>
		<pubDate>Sun, 03 Oct 2010 03:10:23 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-555</guid>
		<description>Shashi, 
 I typically do not reply to posts on any website whatsoever but your scenario may lead others to infer that the authors post is not a viable and effective option, where in fact it indeed is.
There are a couple problems with your posted scenario:
showtopEntries = reader[&quot;showTopentries&quot;] == DbNull.Value ? null : Convert.ToInt32(reader[&quot;showTopEntries&quot;])
1. I am assuming that you have declared showtopEntries as an Integer as you are converting one of the conditions to an Integer. Based on that assumption, you will not be able to implicitly assign a null value to an Integer as an Integer is a value type. One could assign null to a reference type such as a string. In C# a null value is the absence of anything and therefore not a value.
2. I realize that the author of this post has a typo within the declaration of the initial Integer, showTopeEntries where it should state showTopEntries. That said, C# is still a case sensitive language so if you mirrored the example above and remedied the typo, you will still need to ensure that the case is correct.
If you require an Integer as the result try the following scenario: int intShowTopEntries;
intShowTopEntries = reader[&quot;showTopEntries&quot;] == DbNull.Value ? 0 : Convert.ToInt32(reader[&quot;showTopEntries&quot;]);
If you require for example a string as the result try the following scenario: string ShowTopEntries;
ShowTopEntries = reader[&quot;showTopEntries&quot;] == DbNull.Value ? null : reader[&quot;showTopEntries&quot;].ToString();</description>
		<content:encoded><![CDATA[<p>Shashi,<br />
 I typically do not reply to posts on any website whatsoever but your scenario may lead others to infer that the authors post is not a viable and effective option, where in fact it indeed is.<br />
There are a couple problems with your posted scenario:<br />
showtopEntries = reader["showTopentries"] == DbNull.Value ? null : Convert.ToInt32(reader["showTopEntries"])<br />
1. I am assuming that you have declared showtopEntries as an Integer as you are converting one of the conditions to an Integer. Based on that assumption, you will not be able to implicitly assign a null value to an Integer as an Integer is a value type. One could assign null to a reference type such as a string. In C# a null value is the absence of anything and therefore not a value.<br />
2. I realize that the author of this post has a typo within the declaration of the initial Integer, showTopeEntries where it should state showTopEntries. That said, C# is still a case sensitive language so if you mirrored the example above and remedied the typo, you will still need to ensure that the case is correct.<br />
If you require an Integer as the result try the following scenario: int intShowTopEntries;<br />
intShowTopEntries = reader["showTopEntries"] == DbNull.Value ? 0 : Convert.ToInt32(reader["showTopEntries"]);<br />
If you require for example a string as the result try the following scenario: string ShowTopEntries;<br />
ShowTopEntries = reader["showTopEntries"] == DbNull.Value ? null : reader["showTopEntries"].ToString();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shashi</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-548</link>
		<dc:creator>Shashi</dc:creator>
		<pubDate>Fri, 24 Sep 2010 14:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-548</guid>
		<description>It doesnt work in the followng scenario 

showtopEntries = reader[&quot;showTopentries&quot;] == DbNull.Value ? null : Convert.ToInt32(reader[&quot;showTopEntries&quot;])</description>
		<content:encoded><![CDATA[<p>It doesnt work in the followng scenario </p>
<p>showtopEntries = reader["showTopentries"] == DbNull.Value ? null : Convert.ToInt32(reader["showTopEntries"])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Style</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-77</link>
		<dc:creator>Style</dc:creator>
		<pubDate>Fri, 29 Jan 2010 08:04:07 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-77</guid>
		<description>thanks =)</description>
		<content:encoded><![CDATA[<p>thanks =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Janus007</title>
		<link>http://dustyreagan.com/if-then-else-shorthand-in-c/comment-page-1/#comment-76</link>
		<dc:creator>Janus007</dc:creator>
		<pubDate>Tue, 23 Dec 2008 12:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://dev.dustyreagan.com/?p=34#comment-76</guid>
		<description>or
showTopEntries = showTopEntries &gt;= totalEntries ?? totalEntries

;)</description>
		<content:encoded><![CDATA[<p>or<br />
showTopEntries = showTopEntries &gt;= totalEntries ?? totalEntries<br />
 <img src='http://dustyreagan.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

