Click here to Skip to main content
15,911,896 members
Home / Discussions / C#
   

C#

 
GeneralRe: Crystal Reports and .net Pin
Braulio Dez28-May-03 3:44
Braulio Dez28-May-03 3:44 
GeneralC# graphics help required urgent. Pin
Hayat28-May-03 0:48
Hayat28-May-03 0:48 
GeneralRe: C# graphics help required urgent. Pin
Hayat30-May-03 0:23
Hayat30-May-03 0:23 
GeneralRe: C# graphics help required urgent. Pin
Hayat30-May-03 0:29
Hayat30-May-03 0:29 
GeneralUpdating data programmatically Pin
totig27-May-03 23:28
totig27-May-03 23:28 
GeneralRe: Updating data programmatically Pin
jtmtv1828-May-03 0:44
jtmtv1828-May-03 0:44 
GeneralRe: Updating data programmatically Pin
totig28-May-03 2:51
totig28-May-03 2:51 
GeneralRe: Updating data programmatically Pin
Rocky Moore28-May-03 3:38
Rocky Moore28-May-03 3:38 
GeneralRe: Updating data programmatically Pin
totig28-May-03 5:16
totig28-May-03 5:16 
GeneralRe: Updating data programmatically Pin
jtmtv1828-May-03 11:20
jtmtv1828-May-03 11:20 
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 

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.