Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming array items 0001, 0002 etc

Tags:

c#

algorithm

I was trying to think an algorithm for naming an array. For example, it will have 1000 items. The names will be 0000, 0001, 0002 etc.

Which is better - the names to be strings or integers?

If int => how can I add the zeros in front?

If strings => wouldn't it be too complicated to find the last digit - increment it, and if it's 9 go to the previous digit. And it's a lot of parsing.

Which do you think is better?

like image 793
petko_stankoski Avatar asked Mar 08 '26 12:03

petko_stankoski


1 Answers

Use integers, but when you display things, convert it to a string and add the leading zeros.

like image 165
NickLH Avatar answered Mar 10 '26 03:03

NickLH