「トランプは作れますか」と問うと、
Here is the complete code for a program that represents a deck of playing cards in C#:
ここから--------------------------------------------------------------------------------------------
csharp
Copy code
class Card
{
public string Suit { get; set; }
public string Rank { get; set; }
}
class Deck
{
private List<Card> cards;
public Deck()
{
cards = new List<Card>();
string[] suits = new string[] { "Spades", "Hearts", "Diamonds", "Clubs" };
string[] ranks = new string[] { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
foreach (var suit in suits)
{
foreach (var rank in ranks)
{
cards.Add(new Card { Suit = suit, Rank = rank });
}
}
}
public List<Card> GetCards()
{
return cards;
}
}
class Program
{
static void Main(string[] args)
{
Deck deck = new Deck();
foreach (var card in deck.GetCards())
{
Console.WriteLine(card.Rank + " of " + card.Suit);
}
Console.ReadLine();
}
}
-------------------------------------------------------------------------------------------------ここまで
This program creates a Card class to represent a playing card, a Deck class to represent a deck of playing cards, and a Main method to create a deck of cards and display its contents. The program generates a standard deck of 52 playing cards and displays the rank and suit of each card.
さらに、visual studioの使い方
エラーの処理1。エラーの処理2。
0 件のコメント:
コメントを投稿