|
| Recent
Articles |

C# - Generic Plug-in Application At work, we are about to build a new internal tool for administration of different systems. We developers need certain applications and the sales department...
C# - Screen Scraping Some say that screen scraping is a lost art because it is no longer an advanced discipline. That may be right, but there are different ways of doing it. Here are some...
C# Stock Quote Class A couple of months ago one of my readers asked me to build a stock quote class that would automatically update the quote. I forgot about it, but then I found the...
Overload Operators The Right Way In C# It's a good rule of thumb to overload the equality operators on classes. That ensures a correct comparison between to class instances of the same type. If you...
C#: Realtime Currency Exchange Class Soon, I'm facing a new project where the need for up-to-date currency exchanges is crucial. This is not the first time I've done this, but I wanted to make a...
Validating Strong Passwords In C# And ASP.NET It's always a good idea to have a password policy when creating new applications. A password policy can vary from project to project, but the important part is just to...
Retrieve Subdomain From A URL In C# I had to come up with a method that retrieved the subdomain from the current web request on an ASP.NET website. I thought that the System.Uri class...
|
|
|
03.15.07 Generate Unique Strings & Numbers In C# By
Mads Kristensen The System.Guid is used whenever we need to generate a unique key, but it is very long.
That's in many cases not an issue, but in a web scenario where it is part of the URL we need to use its string representation which is 36 characters long.
It clutters up the URL and is just basically ugly.
It is not possible to shorten it without loosing some of the uniqueness of the GUID, but we can come a long way if we can accept a 16 character string instead.
We can change the standard GUID string representation:
If you instead want numbers instead of a string, you can do that to but then you need to go up to 19 characters. The following method converts a GUID to an Int64.
The standard GUID is still the best way to ensure the uniqueness even though it isn't 100% unique.
Comments
About the Author: Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.
|
|