Creating a simple virtual card register system in a .NET Core Console App

A simple system that uses C# .NET Core to simulate a virtual credit card creation receiving e-mail as a parameter

Wellington Caires

2021-05-28 3 min read

First of all: Create a Console Application that uses .NET Core instead of .NET Framework.

After starting the project, it will look like this:

Now, we'll create a class that will hold all the information about the credit card!
Move your mouse above your project solution on the right side of the Visual Studio's window (generally is on this side) and do a right-click on your project's name like this and follow the steps: - Click on "
Add" -> Click on "New Item..."

Now we'll create the code file itself, and after that, we'll code!!
Select "
Class" type of file, name it as "CardHolder" (or something that you'll want), and then press "Add":

The code file has been created and will open like that:

Note: The class name is the filename that we created

Now we'll create a "
public class" instead of keeping
only the "
class" on the script.

What kind of information a credit card has?
We'll assume that have: CVV, (obligatory) a number, a holder's name, (obligatory) a holder's e-mail, and a brand.. right? (
Click at the image to expand)

All the non-obligatory vars will be randomly
generated for our program, ok? You can create a "
set" instruction to define the values as your wish, but that isn't our focus for now.

We're using the
Random() class and its function called Next(int minVal, int maxVal) to generate the random values that will create the numbers and access the card brands' list before returning it on the 'brand' string variable.

On the top of the script, we have two strings called "HolderEmail" and "HolderName" to hold e-mail and names, respectively.

Now, going back to our Program.cs class, we'll try out the created "CardHolder" class!
What we're going to do is:
- Create a
HashSet list using HashSet<CardHolder> and adds only one example cardholder using the name and e-mail parameters (remember: the other values are randomly generated, ok?!);
- Print out all the information of the available cards on the list of the cards using the
for each loop.

See below

Next step: Insert your own holder's name and holder's e-mail into the card's list.
Right below the '
foreach' statement, we'll create an informational text that will show the user that the 'Credit Card insertion function' will start and ask him/her to send us some information!

- Remember again: all of the other information will be randomly created when we instantiate the card details!

And.. how do we get back and show all of the inserted cards?
R: For now, we'll use a '
label' loop!

Above your 'foreach' statement, create any name like 'show
_cards_loop" and add a colon right after it: "show_cards_loop:"

Wanna call the label loop? Just insert a "goto 'loop_name';" after-action and 'vuala'!


Now run your application and see the magic happens!

See our project at GitHub!
I've made some changes on it. :)

Get in touch


Twitter: @Ironiiawn

Powered by