C# - What data type is a credit card number?

Sorry if its a bit out of place but I’m hoping there is someone here that knows the answer.

I’m writing a .NET Console Application in C# that when the user inputs a credit card number it will output what type the credit card is.

The problem I have is declaring the variable that holds the credit card number and that I don’t know what data type it is? Is it a string, a ulong or do I have to create an array of characters?

Thanks in advance.

There isn’t any rule set in stone. I’d use a string, you should use whatever makes your life easier and doesn’t hurt your data.

I’m asking since I’m getting errors all over the place when I debug.

So should it look something like this? : string credit_number = "";

Depends on how your software was made, in a vacuum yes, this way is just fine.
There isn’t anything special about credit card data in this context.

1 Like

In the CS50 course, there was an assignment to build basically the same console application but in C. If I remember correctly, we had to use an unsigned long. Though I guess it works as a strong too.

1 Like

Well, you need to be looking at specific digits to determine card provider so a string representation will be the easiest.

And If you’ll be doing Luhn calculation, it’s also easier to extract specific digit locations on the card number if it’s a string, rather than a numeric variable.

2 Likes