WriteAllLines/ReadAllLines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cody

    #1

    WriteAllLines/ReadAllLines

    The new .NET 2.0 methods in class System.IO.File WriteAllLines and
    ReadAllLines are both taking a string[] as argument or return value.

    Wouldn't it be more flexible to use IEnumerable<str ingfor that? Aren't
    there guidelines which are saying so? Am I missing something?

    Am I the only one with the feeling that lot of the additions to the 2.0
    framework are not well thought through, like the funny DateTime2
    structure or System.String now having a Contains(string ) method but no
    method for containing a char?
  • Paul Hadfield

    #2
    Re: WriteAllLines/ReadAllLines

    Well I suppose the great thing about DotNet is you can quickly create your
    own toolkit that wraps up both classes and provides that functionality. But
    straight away I think you run into the question of would you want
    ReadAllLines to return an instance of "IEnumerable<st ring>" or an instance
    of a class that implements that interface - sometimes you may want a
    List<string>, sometimes you may want a ReadOnlyCollect ion<string>.

    - Paul

    "cody" <deutronium@gmx .dewrote in message
    news:OLSdsZ2pHH A.4100@TK2MSFTN GP04.phx.gbl...
    The new .NET 2.0 methods in class System.IO.File WriteAllLines and
    ReadAllLines are both taking a string[] as argument or return value.
    >
    Wouldn't it be more flexible to use IEnumerable<str ingfor that? Aren't
    there guidelines which are saying so? Am I missing something?
    >
    Am I the only one with the feeling that lot of the additions to the 2.0
    framework are not well thought through, like the funny DateTime2 structure
    or System.String now having a Contains(string ) method but no method for
    containing a char?

    Comment

    • cody

      #3
      Re: WriteAllLines/ReadAllLines

      Paul Hadfield wrote:
      Well I suppose the great thing about DotNet is you can quickly create your
      own toolkit that wraps up both classes and provides that functionality. But
      straight away I think you run into the question of would you want
      ReadAllLines to return an instance of "IEnumerable<st ring>" or an instance
      of a class that implements that interface - sometimes you may want a
      List<string>, sometimes you may want a ReadOnlyCollect ion<string>.
      >
      - Paul
      >
      "cody" <deutronium@gmx .dewrote in message
      news:OLSdsZ2pHH A.4100@TK2MSFTN GP04.phx.gbl...
      >The new .NET 2.0 methods in class System.IO.File WriteAllLines and
      >ReadAllLines are both taking a string[] as argument or return value.
      >>
      >Wouldn't it be more flexible to use IEnumerable<str ingfor that? Aren't
      >there guidelines which are saying so? Am I missing something?
      >>
      >Am I the only one with the feeling that lot of the additions to the 2.0
      >framework are not well thought through, like the funny DateTime2 structure
      >or System.String now having a Contains(string ) method but no method for
      >containing a char?
      >
      Looking with reflektor into the method I see they create an ArrayList
      and then call ToArray() on at before returning it, which wouldn't be
      necessary with IEnumerable<str ing>.

      With IEnumerable they also could return a special enumerator where
      calling enumerator.Move Next() would read the next line, which would have
      the downside that they would have to keep the file open but this was
      just an example of which would be possible.

      Also bad is that if you already have an Enumerable or ArrayList or
      whatever and you want to call WriteAllLines. You will have to copy your
      collection into an array first. You also can't use WriteAllLines with
      your own enumerator which yields string values on demand.

      My whole point is that these functions are pointless (no pun intended)
      They are more than limiting as they are defined, why inventing them in
      the first place.

      Maybe MS should more often make use of FXCop which would have told them
      that they shouldn't make an argument of type array when you only do a
      foreach on it.

      Comment

      Working...