问题
How can I program a Serial Number Generator that generates serial numbers for some existing software?
回答1:
You don't state any specific requirements but you can use a GUID.
Guid mySerialNumber = Guid.NewGuid();
回答2:
I have used this CodeProject Article before when I've needed to do the same thing for projects I have worked on recently. I found it very detailed and while I didn't use everything in the sample I did get a lot out of it. (I have no affiliation with CodeProject or the author)
Additionally there is a library which gives you all this functionality complete with license file replacement and heaps of other features, but its not free, and unfortunately I couldn't remember the link. I'm sure a bit of Googgling and you'll find it.
回答3:
public static string GetSerialKeyAlphaNumaric(SNKeyLength keyLength)
{
string newSerialNumber = "";
string SerialNumber=Guid.NewGuid().ToString("N").Substring(0, (int)keyLength).ToUpper();
for(int iCount=0; iCount < (int) keyLength ;iCount +=4)
newSerialNumber = newSerialNumber + SerialNumber.Substring(iCount, 4) + "-";
newSerialNumber = newSerialNumber.Substring(0, newSerialNumber.Length - 1);
return newSerialNumber;
}
回答4:
Try a number you can test using Luhn's algorithm. That way, you can make it long an inscrutable, yet still easily confirmed. The article contains a link to a C# implementation.
来源:https://stackoverflow.com/questions/1732480/how-to-create-serial-number-generator