DeckOfPlayingCards 2.0.0

dotnet add package DeckOfPlayingCards --version 2.0.0
                    
NuGet\Install-Package DeckOfPlayingCards -Version 2.0.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="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeckOfPlayingCards" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DeckOfPlayingCards" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DeckOfPlayingCards --version 2.0.0
                    
#r "nuget: DeckOfPlayingCards, 2.0.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.
#:package DeckOfPlayingCards@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DeckOfPlayingCards&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DeckOfPlayingCards&version=2.0.0
                    
Install as a Cake Tool

Deck of playing cards

Nuget

Table of Contents

About

With this library, you can create a standard deck of 52 cards, shuffle it, and draw cards from it. You can also reset the deck if you want to run it again. This library can be used to create popular card games such as poker or blackjack. You can also create custom decks using the default set of cards, allowing you to play multi-deck blackjack or "oops all jacks" poker.

Features

This library includes the following types:

  • Entities:
    • Card.cs
    • Deck.cs
  • Enums:
    • CardRank.cs
    • CardSuit.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 standard 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 increments the index by 1. This is how already drawn cards can be put back into the deck in the same order.

For the source code, check out the GitHub repo.

Installation

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

nuget install DeckOfPlayingCards

Usage

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.
deck.Shuffle();

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

// 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.

// Let's see what cards we got!
Console.WriteLine(firstCard);
Console.WriteLine(secondCard);

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

// Just kidding! I play fair.
deck = Deck.Get();
deck.Shuffle(random: new Random(103413));

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 net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DeckOfPlayingCards:

Package Downloads
CasinoSuite.Poker

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
2.0.0 132 4/12/2026
1.2.0 517 10/21/2023
1.1.2 257 10/18/2023
1.1.1 327 10/14/2023
1.1.0 250 10/14/2023
1.0.0 240 9/20/2023

See https://github.com/LarsGast/DeckOfPlayingCards/releases/tag/V2.0.0 for more info.
- Rename package from "Deck of cards" to "Deck of playing cards"
- BREAKING: Now targets .NET 10 instead of .NET 7
- BREAKING: removed Card.getDisplayString()
- BREAKING: removed Rank.getDisplayString()
- BREAKING: removed Suit.getDisplayString()
- BREAKING: Card is now a record struct instead of a class
- BREAKING: All methods and properties are now PascalCase instead of camelCase
- BREAKING: Moved the Rank enum to its own file
- BREAKING: Renamed Rank enum to CardRank
- BREAKING: Moved the Suit enum to its own file
- BREAKING: Renamed Suit enum to CardSuit
- BREAKING: Updated namespaces for all types
- Fixed an issue where the current top non-drawn card would not be shuffled if `includeDrawnCards` was set to false
- Fixed an issue where multiple of the same card would get removed after shuffling if `includeDrawnCards` was set to false