I have to get serial number that include Member that getting from the user and adding to the member serial number of 4 digit.
if I got 888 the newMemberId will be 8880001, and in the next loop 8880002 and so on, the problem is when getting to index of ten I will get 888010 with this code. why?
while (dbNof.AllMembers.Any(x => x.MemberId == newMemberId))
{
numerator++;
newMemberId = Member +
numerator.ToString().PadLeft(5-numerator.ToString().Length, '0');
}
If you want formatted output (at least 4 digits in your case) use formatting:
newMemberId = Member + numerator.ToString("d4");
Or (string interpolation):
newMemberId = $"{Member}{numerator:d4}";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With