Click here to Skip to main content
15,921,351 members
Home / Discussions / C#
   

C#

 
QuestionE-Mails Moderator. Pin
Asare27-Oct-05 8:04
Asare27-Oct-05 8:04 
AnswerRe: E-Mails Moderator. Pin
Dave Kreskowiak27-Oct-05 14:26
mveDave Kreskowiak27-Oct-05 14:26 
AnswerRe: E-Mails Moderator. Pin
Christian Graus27-Oct-05 15:04
protectorChristian Graus27-Oct-05 15:04 
AnswerRe: E-Mails Moderator. Pin
Michael Hendrickx28-Oct-05 0:10
Michael Hendrickx28-Oct-05 0:10 
QuestionE-Mails Moderator. Pin
Asare27-Oct-05 8:03
Asare27-Oct-05 8:03 
QuestionHow to create Plug-in for an application Pin
Anindya Chatterjee27-Oct-05 7:00
Anindya Chatterjee27-Oct-05 7:00 
AnswerRe: How to create Plug-in for an application Pin
Gary Thom27-Oct-05 7:16
Gary Thom27-Oct-05 7:16 
QuestionEnums and Ints Pin
budidharma27-Oct-05 6:41
budidharma27-Oct-05 6:41 
I'm confused on how to convert between enum types and integer types effeciently. Here's the code I'm working with:


public enum Rank
{
Hearts = 0, Diamonds = 1, Spades = 3, Clubs = 4
}

public enum Suit
{
Deuce = 0, Trey = 1, Four = 2, Five = 3, Six = 4, Seven = 5, Eight = 6,
Nine = 7, Ten = 8, Jack = 9, Queen = 10, King = 11, Ace = 12
}

Inside the card, the rank and suit are stored as:
Rank rank;
Suit suit;

The point being: I have a function shuffle which shuffles the deck using for loops.

public void Shuffle()
{
FillDeck();
Card tempCard = new Card();
Random rInt = new Random();

for (int i = 0; i < 100; i++)
{
int first = rInt.Next(51);
int second = rInt.Next(51);

// Copy deck[first] to tempCard
// Copy deck[second] to deck[first]
// Copy tempCard to deck[second]

tempCard.Set(deck[first].Rank, deck[first].Suit);
deck[first].Set(deck[second].Rank, deck[second].Suit);
deck[second].Set(tempCard.Rank, tempCard.Suit);
}

}

I'm attemping to pass integer values from the for loops into the Set function of card which takes Rank and Suit parameters. It's obviously causing errors.

Can I simply typecast an integer to the equivalent suit or rank like so without causing problems, and is it proper programming practice or is there a better way to do it?

tempCard.Set( (Rank)deck[first].Rank, (Suit)deck[first].Suit );
AnswerRe: Enums and Ints Pin
whizzs27-Oct-05 8:56
whizzs27-Oct-05 8:56 
GeneralRe: Enums and Ints Pin
budidharma27-Oct-05 9:12
budidharma27-Oct-05 9:12 
GeneralRe: Enums and Ints Pin
budidharma27-Oct-05 9:28
budidharma27-Oct-05 9:28 
GeneralRe: Enums and Ints Pin
[Marc]27-Oct-05 12:29
[Marc]27-Oct-05 12:29 
GeneralRe: Enums and Ints Pin
whizzs28-Oct-05 3:38
whizzs28-Oct-05 3:38 
QuestionWindowses in C# Pin
Stanciu Vlad27-Oct-05 6:30
Stanciu Vlad27-Oct-05 6:30 
AnswerRe: Windowses in C# Pin
enjoycrack27-Oct-05 10:22
enjoycrack27-Oct-05 10:22 
AnswerRe: Windowses in C# Pin
Stanciu Vlad27-Oct-05 21:39
Stanciu Vlad27-Oct-05 21:39 
Questionproblem aborting a thread on shutdown Pin
Dan Neely27-Oct-05 6:01
Dan Neely27-Oct-05 6:01 
AnswerRe: problem aborting a thread on shutdown Pin
Dan Neely27-Oct-05 7:45
Dan Neely27-Oct-05 7:45 
QuestionBinary Serialization &amp; Webserver Pin
Gilad Kapelushnik27-Oct-05 5:45
Gilad Kapelushnik27-Oct-05 5:45 
QuestionInstaller for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 5:40
Xiangyang Liu 刘向阳27-Oct-05 5:40 
AnswerRe: Installer for C# app Pin
Joshua Quick27-Oct-05 7:17
Joshua Quick27-Oct-05 7:17 
GeneralRe: Installer for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 8:12
Xiangyang Liu 刘向阳27-Oct-05 8:12 
GeneralRe: Installer for C# app Pin
Xiangyang Liu 刘向阳27-Oct-05 10:32
Xiangyang Liu 刘向阳27-Oct-05 10:32 
GeneralRe: Installer for C# app Pin
Joshua Quick27-Oct-05 10:51
Joshua Quick27-Oct-05 10:51 
GeneralRe: Installer for C# app Pin
Dave Kreskowiak27-Oct-05 14:25
mveDave Kreskowiak27-Oct-05 14:25 

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.