<?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>FormatException &#187; logical operators</title>
	<atom:link href="http://www.formatexception.com/tag/logical-operators/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.formatexception.com</link>
	<description>Ramblings on developing in the Windows World</description>
	<lastBuildDate>Fri, 23 Sep 2011 15:34:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>be ^ !be</title>
		<link>http://www.formatexception.com/2008/09/be-be/</link>
		<comments>http://www.formatexception.com/2008/09/be-be/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 22:19:46 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[logical operators]]></category>
		<category><![CDATA[often unused operators]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=7</guid>
		<description><![CDATA[ Unlike the &#38; and &#124; logical operators which seem to have dubious use the ^ (XOR, exclusive or) logical operator can make things quite a bit easier. For instance ever write a IComparable? rather then: if (o1 == null &#38;&#38; o2 != null)     return false; if (o1 != null &#38;&#38; o2 == null)    [...]]]></description>
			<content:encoded><![CDATA[<p><!--StartFragment --> Unlike the &amp; and | logical operators which seem to have dubious use the<br />
^ (XOR, exclusive or) logical operator can make things quite a bit easier.</p>
<p>For instance ever write a IComparable?</p>
<p>rather then:</p>
<p>if (o1 == null &amp;&amp; o2 != null)<br />
    return false;<br />
if (o1 != null &amp;&amp; o2 == null)<br />
   return false;</p>
<p>you can just do:<br />
if(o1 == null ^ o2 == null)<br />
   return false;</p>
<p>like the other logical operators both sides of the conditional must be<br />
evaluated but since we&#8217;re doing exclusive or-ing here it makes sense to<br />
do it rather then in the cases of the other logical operators where fail<br />
fast (or short-circuiting) conditional operators (like &amp;&amp; and ||) would<br />
work better.</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fbe-be%2F&amp;t=be%20%5E%20%21be" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2008%2F09%2Fbe-be%2F&amp;t=be%20%5E%20%21be" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2008/09/be-be/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

