Wrox Programmer Forums
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2009, 10:44 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default compare int with enum

Hi,

A c# book showed a piece of code in which the guy compared int and enum without casting. I don't believe this is correct, at least not with 3.5, my question is whether this was allowed in earlier versions. Or maybe I simply miss something...

Thanks,
Peter
 
Old February 15th, 2009, 11:27 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I'm pretty sure this is legal in Visual Basic with implicit conversion enabled, since enums can be converted to integer values with no loss of data.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
 
Old February 16th, 2009, 12:09 AM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

In c#, enum can inherit from things like long, so convert to int can lose info at times.





Similar Threads
Thread Thread Starter Forum Replies Last Post
enum 2 names OneQuestion General .NET 4 January 2nd, 2008 02:50 PM
Enum gets initalized to first value mhshpk ASP.NET 2.0 Professional 2 September 4th, 2007 10:16 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
Using Enum Type Mike2000 VB.NET 2002/2003 Basics 2 June 5th, 2003 05:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.