• Have any questions?
  • Coming Soon!
  • Support@earnfreerecharge.com
How to generate a unique number at every post API call in asp.net core?
How to generate a unique number at every post API call in aspnet core

How to generate a unique number at every post API call in asp.net core?

Many times we come across a situation where we require a unique number for various purposes. Please continue if you want to know how to generate a unique number in the asp.net c# code behind.

We all know that the date and time is something which is the only constant variable. I mean to say that date and time changes every moment and we can make use of these changing ticks. We can form up a number using the day, month, year, hour, minute, second, and milliseconds.

Please see the below c# method which returns a unique number:

DateTime dt = DateTime.UtcNow();
int unique_number = dt.Day.ToString() + dt.Month + dt.Year + dt.Hour + dt.Minute + dt.Second + dt.Millisecond;

In the above code - we have consider UTC timing and we have concatenated each part of the time one by one.