DeckOfPlayingCards 1.2.0

dotnet add package DeckOfPlayingCards --version 1.2.0
NuGet\Install-Package DeckOfPlayingCards -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeckOfPlayingCards" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeckOfPlayingCards --version 1.2.0
#r "nuget: DeckOfPlayingCards, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DeckOfPlayingCards as a Cake Addin
#addin nuget:?package=DeckOfPlayingCards&version=1.2.0

// Install DeckOfPlayingCards as a Cake Tool
#tool nuget:?package=DeckOfPlayingCards&version=1.2.0

Deck of cards


Table of Contents


This library can be used to create card games such as poker or blackjack. With this library, you can create a standard deck of 52 cards, shuffle it, and draw cards. You can also reset the deck if you want to run it again.


This package includes the following classes:

  • Card.cs
  • Deck.cs
  • ExtensionMethods.cs

The Card.cs class is a simple class for storing the rank and the suit of the card. The Deck.cs class contains a list of cards as a property. It also includes the following methods:

  • get()
    • Gets a standards deck of 52 cards, not shuffled.
    • If specified, you can create a deck with your own set of cards.
  • shuffle()
    • Shuffles the deck.
    • Includes a parameter to specify whether the already drawn cards should be shuffled back into the deck.
    • A Random variable can be passed in. If not, a Random variable is initialized.
  • draw()
    • Draws a card from the deck.
    • Returns the drawn card
  • reset()
    • Resets the deck, meaning all drawn cards will be put back onto the deck in the same order as they were originally.

The draw() method doesn't remove a card from the deck, it simply returns the card at the current index and moves the index up by 1. This is how already drawn cards can be put back into the deck in the same order.

The ExtensionMethods.cs class contains extension methods for the Card.Rank and Card.Suit enums. These methods can be called to create a display string for the rand and the suit of the card. For example: the display string of the Ten of Hearts is T♥.

For the source code, check out the GitHub repo.


To use Deck of Cards in your project, you can install it via NuGet Package Manager:

nuget install DeckOfPlayingCards


Getting a deck, shuffling it, drawing cards, and resetting it is pretty straightforward. See the code snippet below.

using DeckOfCardsLibrary;

// Get a standard unshuffled deck.
var deck = Deck.get();

// Shuffle the deck.

// Draw some cards.
var firstCard = deck.draw()!;
var secondCard = deck.draw()!;

// Keep in mind that deck.draw() returns null if all the cards in the deck have already been drawn.
// In this case I have only drawn two cards, so I can safely say the method does not return null.

// I'll display them in a way that is easy on the eye.
// The rank "10" will be displayed as "T" here to make sure the display string will always be two characters.
Console.WriteLine(firstCard.getDisplayString(displayTenAsT: true));
Console.WriteLine(secondCard.getDisplayString(displayTenAsT: true));

// That was a good hand! Let's reset the deck so I get the same cards again.

// Just kidding! I play fair.
deck = Deck.get();
deck.shuffle(random: new Random(915));

The GitHub repo also includes a console app which you can play around with.

Contributing and Feedback

If you have questions, concerns, or would like to contribute to this project, there are several ways to get involved:

  • Open an Issue: If you encounter a bug, have a feature request, or want to discuss improvements, please open an issue.

  • Start a Discussion: You can also initiate a discussion in the Discussions section of this repository to share ideas or seek help.

  • Fork and Contribute: If you'd like to make changes or enhancements to the project, fork the repository and submit a pull request with your proposed changes.

Your contributions and feedback are highly valued and essential to the improvement of this project. Thank you for your support!

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DeckOfPlayingCards:

Package Downloads

A comprehensive library for working with poker hands and cards in C#. This library includes classes for representing poker hands, cards, and offers utility methods for evaluating and comparing poker hands.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 244 10/21/2023
1.1.2 110 10/18/2023
1.1.1 106 10/14/2023
1.1.0 99 10/14/2023
1.0.0 103 9/20/2023

- Added the possibility to create your own custom deck.
- Added a public property `cards` to the Deck class