Re: CStr() vs. .ToString()




"guy" <guy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2199BA10-0B41-4D7D-B7AF-F34D469457BD@xxxxxxxxxxxxxxxx
both points of view are valid, however i use the vb string methods as the
compiler makes optimzations that can improve performance over the native
.Net
methods, also i find the vb methods read better.

The VB 6.0 way are not methods, they are functions. The .NET way are object
methods. The VB.NET compiler does NOT optimize the VB 6.0 functions to work
BETTER than the natvie .NET object methods.

To answer your question, ToString would be my suggestion, rather than
CStr(). ToString is a method of the Object Type, and since all classes
inherit from Object, all objects have this method.



cheers

guy

"Scott M." wrote:

IMHO (and this has been debated for quite some time now), you should view
all of the old "data-type" specific functions as legacy functions and no
longer use them. Instead, use the more object-oriented methods of a
type.

CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
.ToString
All date/time functions would be replaced with methods and properties of
the
Date class
All string functions would be replaced with methods and properties of the
String class.

et all.


"Sean" <Sean@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@xxxxxxxxxxxxxxxx
Book I am reading says that Cstr() is best method for efficency and
safety
however it doesnt compare that method of the .ToString() method.

Which is best.

Thanks







.



Relevant Pages

  • Re: CStr() vs. .ToString()
    ... all of the old "data-type" specific functions as legacy functions and no ... CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or .ToString ... All string functions would be replaced with methods and properties of the ... String class. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Why does x.ToString() throw an error if x == null?
    ... Michael C wrote: ... have initialized it and the compiler has not set aside any space for ... The actual function called depends on the actual run-time type of the ... ToString implementation. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: c# interview question
    ... uses the ToString() method anyway. ... between the two would have been optimized away by the compiler, ... If you're writing code where these differences are ... significant, use C or C++, or even Assembly language. ...
    (microsoft.public.dotnet.languages.csharp)
  • Why doesnt the compiler use ToString for implicit conversions?
    ... expression where a String is expected. ... MyClass in MyNamespace and don't override ToString, ... The compiler will complain that myObject cannot be cast to String. ... conversion on realizing that myObject should be converted to String? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Why doesnt the compiler use ToString for implicit conversions?
    ... By requiring the use of the ToString() method in code, ... But you (and the compiler) can still call the base definition. ... Mattias Sjögren mattias @ mvps.org ...
    (microsoft.public.dotnet.languages.vb)