Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
GeneralXML Loading Problem Pin
Nick Parker27-May-03 17:10
protectorNick Parker27-May-03 17:10 
GeneralRe: XML Loading Problem Pin
J. Dunlap27-May-03 20:21
J. Dunlap27-May-03 20:21 
GeneralRe: XML Loading Problem Pin
Nick Parker28-May-03 1:43
protectorNick Parker28-May-03 1:43 
GeneralGrabbing Text Input with C# / .net Pin
dratti27-May-03 12:41
dratti27-May-03 12:41 
GeneralInstantiate .NET type within web page (like ActiveX) Pin
Michal Januszczyk27-May-03 10:15
sussMichal Januszczyk27-May-03 10:15 
GeneralRe: Instantiate .NET type within web page (like ActiveX) Pin
Vasudevan Deepak Kumar27-May-03 19:52
Vasudevan Deepak Kumar27-May-03 19:52 
GeneralRe: Instantiate .NET type within web page (like ActiveX) Pin
Ed K30-May-03 3:49
Ed K30-May-03 3:49 
GeneralGood Enum Question Pin
Ed K27-May-03 9:26
Ed K27-May-03 9:26 
One of the guys here posted a good question regarding enums. Basically questioning type safety with enums. Given the following:
using System;

namespace Poker
{
	class PokerTable
	{

		[STAThread]
		static void Main(string[] args)
		{
                        // this errors
			PlayingCard fiveOfHearts = new PlayingCard( 4, 1 );
                        // works
			PlayingCard fiveOfHearts = new PlayingCard( (PlayingCard.Rank) 4, (PlayingCard.Suit) 1 );
			fiveOfHearts.ViewHand();
                        // works
			PlayingCard rulesCard = new PlayingCard( (PlayingCard.Rank) 343, (PlayingCard.Suit) (-1) );
			rulesCard.ViewHand();
                        // why does this work?
			PlayingCard emptyHand = new PlayingCard( 0, 0 );
			emptyHand.ViewHand();

			Console.In.ReadLine();
		}
	}


	public class PlayingCard 
	{
		public enum Suit 
		{
			SPADES, HEARTS, DIAMONDS, CLUBS
		}
		public enum Rank 
		{
			ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN,
			EIGHT, NINE, TEN, JACK, QUEEN, KING
		}

		private Rank rank;
		private Suit suit;

		public PlayingCard( Rank rank, Suit suit ) 
		{
			this.rank = rank;
			this.suit = suit;
		}

		public void ViewHand()
		{
			Console.WriteLine(rank + " " + suit);
		}
	}
}


Why is PlayingCard( 0, 0 ) acceptable? Shouldn't this have a compile time error as does PlayingCard( 4, 1 )? I would think they should both fail!

Thanks!

ed

Regulation is the substitution of error for chance.
GeneralRe: Good Enum Question Pin
Eric Gunnerson (msft)27-May-03 11:29
Eric Gunnerson (msft)27-May-03 11:29 
GeneralRe: Good Enum Question Pin
ralfoide27-May-03 14:08
ralfoide27-May-03 14:08 
GeneralRe: Good Enum Question Pin
Eric Gunnerson (msft)27-May-03 17:43
Eric Gunnerson (msft)27-May-03 17:43 
GeneralRe: Good Enum Question Pin
J. Dunlap27-May-03 14:11
J. Dunlap27-May-03 14:11 
GeneralRe: Good Enum Question Pin
KingTermite27-May-03 11:32
KingTermite27-May-03 11:32 
GeneralRe: Good Enum Question Pin
Rein Hillmann27-May-03 15:26
Rein Hillmann27-May-03 15:26 
GeneralRe: Good Enum Question Pin
leppie28-May-03 6:57
leppie28-May-03 6:57 
GeneralInteraction between a Form and a Class Pin
JJF00727-May-03 8:21
JJF00727-May-03 8:21 
GeneralRe: Interaction between a Form and a Class Pin
KingTermite27-May-03 14:28
KingTermite27-May-03 14:28 
GeneralWhitespaceHandling Pin
Kant27-May-03 5:30
Kant27-May-03 5:30 
GeneralRe: WhitespaceHandling Pin
Philip Fitzsimons27-May-03 22:26
Philip Fitzsimons27-May-03 22:26 
GeneralRe: WhitespaceHandling Pin
Kant28-May-03 5:01
Kant28-May-03 5:01 
GeneralRe: WhitespaceHandling Pin
Philip Fitzsimons28-May-03 5:06
Philip Fitzsimons28-May-03 5:06 
GeneralRe: WhitespaceHandling Pin
Kant28-May-03 6:13
Kant28-May-03 6:13 
GeneralRe: WhitespaceHandling Pin
Philip Fitzsimons28-May-03 6:19
Philip Fitzsimons28-May-03 6:19 
GeneralRe: WhitespaceHandling Pin
Kant28-May-03 6:38
Kant28-May-03 6:38 
GeneralDataBinding and Update Pin
DionChen27-May-03 3:36
DionChen27-May-03 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.