Tuesday, September 6, 2011

How would you optimize this piece of C# code?

csharpI’ve been digging into some code lately when getting into an existing project, and came across these two lines:
if (Math.Max(thisString.Length, otherString.Length) > Math.Pow(2, 31))
throw new ArgumentException("String too long");

Looking at the code I see right away that this is ported from some other language over to C#. It’s quite easy to optimize it…. how would you do it?