I wouldn't use an random number: I use a Guid instead:
Guid g = Guid.NewGuid();
SaveToDatabaseAsActivationCode(g);
SendToEmailWithRegistratcionLetter(g.ToString());
"Hello Sir,
Plz explain me the above code, what is the work of Guid and what is the use of these lines..
SaveToDatabaseAsActivationCode(g);
SendToEmailWithRegistratcionLetter(g.ToString());"
A Guid is basically a 128 bit number, which is generated by the system on demand. It is called a Globally Unique IDentifier - which is where the "GUID" bit comes in - and it is commonly used for database ID fields, because the chances of you generating two identical GUID values in your application are higher than the chances of you winning the lottery.
This weekend.
And next weekend, and every single weekend until the end of your life.
The odds are absolutely staggering!
I use them in registration to provide a unique code I can tie up with a user ID and confirm an email address: Send the user an email to his registered address, with teh body as HTML, with a link back to a "Registration complete" page using a query string containing the userID and the GUID. A quick check in the DB that we are waiting for a link from that userID with that GUID, and all if fine.
The two method calls are just examples for you: the names are supposed to indicate the two actions you would need to do with the GUIDwhen you have generated it, and to show that Guid supports the ToString method to produce a "human readable" version.