<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: C# Enum Craziness: Sometimes What You Expect Isn&#8217;t The Case</title>
	<atom:link href="http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/feed/" rel="self" type="application/rss+xml" />
	<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/</link>
	<description>Blogs are the new phonebook</description>
	<lastBuildDate>Sat, 28 Mar 2009 03:53:56 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vipin Misys</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1847</link>
		<dc:creator>Vipin Misys</dc:creator>
		<pubDate>Thu, 06 Nov 2008 08:59:39 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1847</guid>
		<description>Good Article.Does it mean that we can&#039;t trust ENUM anymore :)

Thanks</description>
		<content:encoded><![CDATA[<p>Good Article.Does it mean that we can&#8217;t trust ENUM anymore <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Enums are Ints that Ain&#8217;t &#171; Infovark Underground</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1842</link>
		<dc:creator>Enums are Ints that Ain&#8217;t &#171; Infovark Underground</dc:creator>
		<pubDate>Mon, 28 Jul 2008 14:42:35 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1842</guid>
		<description>[...] researching something to do with the new System.Addin namespace in C# 3.5, I was reminded of some enum craziness I&#8217;d [...]</description>
		<content:encoded><![CDATA[<p>[...] researching something to do with the new System.Addin namespace in C# 3.5, I was reminded of some enum craziness I&#8217;d [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: W&#246;chentliche Rundablage: ASP.NET, ASP.NET MVC, System.AddIn, Silverlight, LINQ, C# 3.0, WPF, XBAP&#8230; &#124; Code-Inside Blog</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1785</link>
		<dc:creator>W&#246;chentliche Rundablage: ASP.NET, ASP.NET MVC, System.AddIn, Silverlight, LINQ, C# 3.0, WPF, XBAP&#8230; &#124; Code-Inside Blog</dc:creator>
		<pubDate>Mon, 04 Feb 2008 19:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1785</guid>
		<description>[...] C# Enum Craziness: Sometimes What You Expect Isn’t The Case [...]</description>
		<content:encoded><![CDATA[<p>[...] C# Enum Craziness: Sometimes What You Expect Isn’t The Case [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NinjaCross</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1777</link>
		<dc:creator>NinjaCross</dc:creator>
		<pubDate>Tue, 29 Jan 2008 10:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1777</guid>
		<description>It&#039;s strange that no recommendations and specific hints are given in the official c# specs.
Anyway, I absolutely agree with the explanation made by James Curran.
Thanks Luke for pointing to this very important aspect of Enums</description>
		<content:encoded><![CDATA[<p>It&#8217;s strange that no recommendations and specific hints are given in the official c# specs.<br />
Anyway, I absolutely agree with the explanation made by James Curran.<br />
Thanks Luke for pointing to this very important aspect of Enums</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: leppie</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1776</link>
		<dc:creator>leppie</dc:creator>
		<pubDate>Tue, 29 Jan 2008 08:10:27 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1776</guid>
		<description>Enum.IsDefined() should be used.</description>
		<content:encoded><![CDATA[<p>Enum.IsDefined() should be used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #20</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1775</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #20</dc:creator>
		<pubDate>Tue, 29 Jan 2008 08:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1775</guid>
		<description>[...] C# Enum Craziness: Sometimes What You Expect Isn’t The Case « Spontaneous Publicity - Luke Foust talks about some of the stranger behaviour of the enum [...]</description>
		<content:encoded><![CDATA[<p>[...] C# Enum Craziness: Sometimes What You Expect Isn’t The Case « Spontaneous Publicity &#8211; Luke Foust talks about some of the stranger behaviour of the enum [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JohnB</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1773</link>
		<dc:creator>JohnB</dc:creator>
		<pubDate>Tue, 29 Jan 2008 02:59:29 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1773</guid>
		<description>Interesting, I get the same results with VB too.</description>
		<content:encoded><![CDATA[<p>Interesting, I get the same results with VB too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Etheredge</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1772</link>
		<dc:creator>Justin Etheredge</dc:creator>
		<pubDate>Tue, 29 Jan 2008 02:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1772</guid>
		<description>Another reason why this behavior can be useful is when it comes to extending enumerations. I came across this recently when working on a Linq provider where there is an ExpressionVisitor class that walks the expression tree. There is a framework enumeration that defines all of the possible expression types, but I can just as easy extend this visitor class to add several of my custom expression types. The ExpressionVisitor uses the enumeration from the framework and enumerations cannot be inherited from, but I can define my own enumeration and specify values that do not overlap with the framework enumeration. I can then pass in values from my new enumeration with no problems. Otherwise I would have to redefine the entire enumeration and add my custom values, then convert to the original enumeration when passing values to the base class. Whether or not this would be a better solution is up for debate. :-)</description>
		<content:encoded><![CDATA[<p>Another reason why this behavior can be useful is when it comes to extending enumerations. I came across this recently when working on a Linq provider where there is an ExpressionVisitor class that walks the expression tree. There is a framework enumeration that defines all of the possible expression types, but I can just as easy extend this visitor class to add several of my custom expression types. The ExpressionVisitor uses the enumeration from the framework and enumerations cannot be inherited from, but I can define my own enumeration and specify values that do not overlap with the framework enumeration. I can then pass in values from my new enumeration with no problems. Otherwise I would have to redefine the entire enumeration and add my custom values, then convert to the original enumeration when passing values to the base class. Whether or not this would be a better solution is up for debate. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Curran</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1771</link>
		<dc:creator>James Curran</dc:creator>
		<pubDate>Mon, 28 Jan 2008 23:57:28 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1771</guid>
		<description>[Flags] is part of it.  The other part is that if the CLR had to verify every int to enum cast against EVERY possible enum value,  your  code would come to a screeching halt.   Consider the code to handle that:

enum MyFlag myflag;
myflag = (int) someInt;

would become (effectively)

enum MyFlag myflag;
bool OK= false;
for(int v in Enum.GetValues(typeof(MyFlag))
{
     if (v == someInt)
     {
          OK= true;
          break;
}
if (!OK)
      throw new InvalidCastException();

myflag = (int) someInt;

Do you really want to go through all that every time you assign an int to an enum?  And remember, this cannot be done as compile time, even if the int being assigned is a constant, as the enum may be defined in a different assembly, and may change between compile &amp; run.</description>
		<content:encoded><![CDATA[<p>[Flags] is part of it.  The other part is that if the CLR had to verify every int to enum cast against EVERY possible enum value,  your  code would come to a screeching halt.   Consider the code to handle that:</p>
<p>enum MyFlag myflag;<br />
myflag = (int) someInt;</p>
<p>would become (effectively)</p>
<p>enum MyFlag myflag;<br />
bool OK= false;<br />
for(int v in Enum.GetValues(typeof(MyFlag))<br />
{<br />
     if (v == someInt)<br />
     {<br />
          OK= true;<br />
          break;<br />
}<br />
if (!OK)<br />
      throw new InvalidCastException();</p>
<p>myflag = (int) someInt;</p>
<p>Do you really want to go through all that every time you assign an int to an enum?  And remember, this cannot be done as compile time, even if the int being assigned is a constant, as the enum may be defined in a different assembly, and may change between compile &amp; run.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Tucholski</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1769</link>
		<dc:creator>Josh Tucholski</dc:creator>
		<pubDate>Mon, 28 Jan 2008 20:08:32 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1769</guid>
		<description>I second their thoughts that this was meant for quick bit-masking.  Take a look at the tutorial I wrote on flags with ASP.NET http://tucholski.blogspot.com/2007/10/dynamic-tab-navigation-wmaster-pages.html</description>
		<content:encoded><![CDATA[<p>I second their thoughts that this was meant for quick bit-masking.  Take a look at the tutorial I wrote on flags with ASP.NET <a href="http://tucholski.blogspot.com/2007/10/dynamic-tab-navigation-wmaster-pages.html" rel="nofollow">http://tucholski.blogspot.com/2007/10/dynamic-tab-navigation-wmaster-pages.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke Foust</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1768</link>
		<dc:creator>Luke Foust</dc:creator>
		<pubDate>Mon, 28 Jan 2008 18:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1768</guid>
		<description>I agree that OR-ing enums together is a feature (although it is rather un-intuitive). I with the compiler could make a distinction between enums which are marked with the [Flags] attribute and those which aren&#039;t meant to be OR-ed together.</description>
		<content:encoded><![CDATA[<p>I agree that OR-ing enums together is a feature (although it is rather un-intuitive). I with the compiler could make a distinction between enums which are marked with the [Flags] attribute and those which aren&#8217;t meant to be OR-ed together.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Sullivan</title>
		<link>http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1767</link>
		<dc:creator>Will Sullivan</dc:creator>
		<pubDate>Mon, 28 Jan 2008 18:30:43 +0000</pubDate>
		<guid isPermaLink="false">http://lfoust.wordpress.com/2008/01/28/c-enum-craziness/#comment-1767</guid>
		<description>I believe the reason why this is possible is to support flags.  In other words, 

[flags()]
public enum MyFlag { unknown = 2, red = 4, blue = 8 }

public MyFlag WhoGotDaFlag = MyFlag.red &#124; MyFlag.blue;

Test that out and see what the int value of WhoGotDaFlag is.  I bet it isn&#039;t 2, 4 or 8.

OR-ing together enum values is an extremely important feature of the CLR, and is used throughout the framework.  I doubt it&#039;ll be changed.</description>
		<content:encoded><![CDATA[<p>I believe the reason why this is possible is to support flags.  In other words, </p>
<p>[flags()]<br />
public enum MyFlag { unknown = 2, red = 4, blue = 8 }</p>
<p>public MyFlag WhoGotDaFlag = MyFlag.red | MyFlag.blue;</p>
<p>Test that out and see what the int value of WhoGotDaFlag is.  I bet it isn&#8217;t 2, 4 or 8.</p>
<p>OR-ing together enum values is an extremely important feature of the CLR, and is used throughout the framework.  I doubt it&#8217;ll be changed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
