Results 1 to 2 of 2

Thread: [2005] String.Format vs Format

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    65

    Thumbs down [2005] String.Format vs Format

    I just noticed through debugging my code that the two following lines produce different results:

    Code:
    String.Format("{0:F4}", 5)
    Returns "5.0000"

    Code:
    Format("{0:F4}", 5)
    Returns "5"

    Can anyone shed some light on this?

    Thanks!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] String.Format vs Format

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width