String formatting in .NET is a pain. Not that it has ever been easy - even COBOL formatting masks can get out of hand, but there's no doubt that the .NET system is harder to grasp and remember than the VB 1-6 scheme...
I just had a need to format an arbitrary value using a user-supplied format string. You'd think that
obj.ToString(format)
would do the trick. Except that System.Object doesn't have that override of ToString(), so that's not a universal solution. So String.Format() is the obvious next choice, except that I need to somehow take a format string like 'N' or 'd' and make it into something valid for String.Format()...
Brad Abrams has some good info. But his problem/solution isn't quite what I needed. Close enough to extrapolate though:
outValue =
Given a format string of 'N', the inner Format() returns "{0:N}", which is then used by the outer Format() to format the actual value.
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2013, Marimer LLC
E-mail