Readability VS Uber Cool One Liners VS Performance
Published - 2010-12-09 | 0min
Given that you need to do a MD5 hash in C#, which approach would you take?
A not so readable but cool one liner:
Or
[Update:] Alex proposed the following, verbose, but as an extension:
1
2
3
4
5
6
7
8
|
public static string CalculateMd5Hash(this String input)
{
return System.Security.Cryptography.MD5
.Create()
.ComputeHash(System.Text.Encoding.Unicode.GetBytes(input))
.Aggregate(new StringBuilder(), (a, b) => a.Append(b.ToString("X2")), a => a)
.ToString();
}
|
What do you think?