I just noticed through debugging my code that the two following lines produce different results:
Returns "5.0000"Code:String.Format("{0:F4}", 5)
Returns "5"Code:Format("{0:F4}", 5)
Can anyone shed some light on this?
Thanks!
Printable View
I just noticed through debugging my code that the two following lines produce different results:
Returns "5.0000"Code:String.Format("{0:F4}", 5)
Returns "5"Code:Format("{0:F4}", 5)
Can anyone shed some light on this?
Thanks!
They are different functions. String.Format is, as the name suggests, a member of the System.String class. Format is a VB.NET Runtime function and is a member of the Microsoft.VisualBasic.Strings module. Like all Runtime functions it has been implemented to mimic the behaviour of the function of the same name in VB6. Don't use Format at all. Use String.Format in all cases.
Runtime functions basically exist for two reasons. To make VB6 developers feel at home and to allow upgraded VB6 code to work as it did in VB6. Don't use any Runtime functions in new code unless you have a specific need of their functionality or they offer some value. There are very few situations where that is the case.