Click here to Skip to main content
14,659,588 members
Home » Discussions » C#
   

C#

 
QuestionNeed help calling a static method Pin
Member 148563427-Jun-20 15:00
MemberMember 148563427-Jun-20 15:00 
AnswerRe: Need help calling a static method Pin
OriginalGriff7-Jun-20 20:29
mveOriginalGriff7-Jun-20 20:29 
QuestionCard shuffle program code help needed Pin
Brian_TheLion7-Jun-20 3:57
MemberBrian_TheLion7-Jun-20 3:57 
AnswerRe: Card shuffle program code help needed Pin
Dave Kreskowiak7-Jun-20 4:03
mveDave Kreskowiak7-Jun-20 4:03 
GeneralRe: Card shuffle program code help needed Pin
OriginalGriff7-Jun-20 4:14
mveOriginalGriff7-Jun-20 4:14 
GeneralRe: Card shuffle program code help needed Pin
Dave Kreskowiak7-Jun-20 8:05
mveDave Kreskowiak7-Jun-20 8:05 
GeneralRe: Card shuffle program code help needed Pin
Brian_TheLion8-Jun-20 19:17
MemberBrian_TheLion8-Jun-20 19:17 
GeneralRe: Card shuffle program code help needed (code included) Pin
Brian_TheLion7-Jun-20 15:27
MemberBrian_TheLion7-Jun-20 15:27 
<pre lang="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Card_Shuffle
{
public class Deck
{
private Card[] deck;
private int currentCard;
private const int NUMBER_OF_CARDS = 52;
private Random ranNum;



public Deck()
{
string[] faces = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nin", "Ten", "Jack", "Queen", "King" };
string[] suits = { "Hearts", "Clubs", "Diamonds", "Spades" };
deck = new Card[NUMBER_OF_CARDS];
currentCard = 0;
ranNum = new Random();
for (int count = 0; count < deck.Length; count++)
deck[count] = new Card(faces[count % 11],
suits[count / 13]);
}

public void Shuffle()
{
currentCard = 0;
for (int first = 0; first < deck.Length; first++)
{
int second = ranNum.Next(NUMBER_OF_CARDS);
Card temp = deck[first];
deck[first] = deck[second];
deck[second] = temp;
}
}
public Card DealCard()
{
if (currentCard < deck.Length)
return deck[currentCard++];
else return null;
}

public class Card
{
private string face;
private string suit;
public Card(string cardFace, string cardSuit)
{
face = cardFace;
suit = cardSuit;
}
public override string ToString()
{
return face + " of " + suit;
}

}


static void Main(string[] args)
{
Deck deck1 = new Deck();
deck1.Shuffle();
for (int i = 0; i < 52; i++)
{
Console.Write("0-19)", deck1.DealCard());

if ((i + 1) % 4 == 0)

Console.WriteLine();
}
Console.ReadLine();
}

}
}


</pre>

At the moment I get 13 rows of the below text displayed.
0-19)0-19)0-19)0-19)

Brian
GeneralRe: Card shuffle program code help needed (code included) Pin
Richard MacCutchan7-Jun-20 21:51
mveRichard MacCutchan7-Jun-20 21:51 
GeneralRe: Card shuffle program code help needed (code included) Pin
Brian_TheLion8-Jun-20 19:15
MemberBrian_TheLion8-Jun-20 19:15 
GeneralRe: Card shuffle program code help needed (code included) Pin
Richard MacCutchan8-Jun-20 21:30
mveRichard MacCutchan8-Jun-20 21:30 
GeneralRe: Card shuffle program code help needed (code included) Pin
Richard Deeming8-Jun-20 0:08
mveRichard Deeming8-Jun-20 0:08 
GeneralRe: Card shuffle program code help needed (code included) Pin
Brian_TheLion8-Jun-20 19:01
MemberBrian_TheLion8-Jun-20 19:01 
GeneralRe: Card shuffle program code help needed (code included) Pin
Richard Deeming8-Jun-20 22:16
mveRichard Deeming8-Jun-20 22:16 
GeneralRe: Card shuffle program code help needed (code included) Pin
Brian_TheLion11-Jun-20 18:20
MemberBrian_TheLion11-Jun-20 18:20 
AnswerRe: Card shuffle program code help needed Pin
OriginalGriff7-Jun-20 4:11
mveOriginalGriff7-Jun-20 4:11 
GeneralRe: Card shuffle program code help needed Pin
Brian_TheLion7-Jun-20 15:37
MemberBrian_TheLion7-Jun-20 15:37 
GeneralRe: Card shuffle program code help needed Pin
OriginalGriff7-Jun-20 20:38
mveOriginalGriff7-Jun-20 20:38 
GeneralRe: Card shuffle program code help needed Pin
Brian_TheLion8-Jun-20 19:12
MemberBrian_TheLion8-Jun-20 19:12 
GeneralRe: Card shuffle program code help needed Pin
F-ES Sitecore9-Jun-20 2:31
mveF-ES Sitecore9-Jun-20 2:31 
GeneralRe: Card shuffle program code help needed Pin
Brian_TheLion9-Jun-20 19:56
MemberBrian_TheLion9-Jun-20 19:56 
GeneralRe: Card shuffle program code help needed Pin
Brian_TheLion11-Jun-20 18:17
MemberBrian_TheLion11-Jun-20 18:17 
QuestionBest way to store methods in a database? Pin
arnold_w5-Jun-20 22:42
Memberarnold_w5-Jun-20 22:42 
QuestionRe: Best way to store methods in a database? Pin
Richard MacCutchan5-Jun-20 22:58
mveRichard MacCutchan5-Jun-20 22:58 
AnswerRe: Best way to store methods in a database? Pin
arnold_w5-Jun-20 23:56
Memberarnold_w5-Jun-20 23:56 

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.