Re: [MSH] Use cast or ToString()?



On Tue, 08 Nov 2005 09:17:26 +0000, Chris Warwick
<news@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

>While parsing through a log file and extracting dates from a regex
>into $matches.date, I noticed that I could use either of the following
>to end up with the numeric day of the month (1..31) as a string :
>
>$day=[string]([datetime]$matches.date).day
>
>or
>
>$day=([datetime]$matches.date).day.tostring()
>
>Is it "Better" to use the cast or the ToString() method? Any views?
>
>Thanks,
>Chris


Just thinking about this some more, it occurs to me that the cast
probably ends up invoking the ToString() method anyway - is this the
case? If this it what happens then I'd personally prefer the second
syntax since it states explicitly what should be done...

Keen to hear other views though!

Chris
.



Relevant Pages

  • Re: How do you copy multidimension array from Vector to Object[][] ?
    ... Hi Chris thanks but I cant use ArrayList as I'm using J2ME. ... for now I'll just use the crappy m.elementAtfunction and cast to. ... -- One of the problems with the Collection classes is that you have to ... If you have a performance-intensive app, ...
    (comp.lang.java.programmer)
  • Re: Question on Numeric Formating...
    ... Could you give you kind advice on code? ... technology and I just know how to instantiate the getdecimal or cast the ... > class does not have a ToString function with any parameters. ... >> I'm trying to convert this string into a curreny format type and I'm not ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Which of these is better casting or toString()
    ... casting or toString?? ... I would cast, because it makes it clear that you are expecting a string. ... With a cast it's easier to detect an error, with toString() it isn't. ...
    (comp.lang.java.programmer)
  • Re: Upper/lower Case in C#
    ... If the column is a string you could just cast it instead of calling ... ToString() ... Ignacio Machin, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: operator * cannot be applied
    ... Thanks Chris. ... I used "Cast" to see if anyone would clarify it for me. ... George Hester ... >> That casted the string rate to a double dblrate. ...
    (comp.lang.java.help)