Readability VS Uber Cool One Liners VS Performance

December 9, 2010

Given that you need to do a MD5 hash in C#, which approach would you take?

A not so readable but cool one liner:


A more readable and performance wise approach?

[Update:] Alex proposed the following, verbose, but as an extension:

public static string CalculateMd5Hash(this String input)
    return System.Security.Cryptography.MD5
        .Aggregate(new StringBuilder(), (a, b) => a.Append(b.ToString("X2")), a => a)

What do you think?

comments powered by Disqus