473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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<stringfor 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?
Jun 5 '07 #1
2 4172
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<string>" or an instance
of a class that implements that interface - sometimes you may want a
List<string>, sometimes you may want a ReadOnlyCollection<string>.

- Paul

"cody" <de********@gmx.dewrote in message
news:OL**************@TK2MSFTNGP04.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<stringfor 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?

Jun 5 '07 #2
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<string>" or an instance
of a class that implements that interface - sometimes you may want a
List<string>, sometimes you may want a ReadOnlyCollection<string>.

- Paul

"cody" <de********@gmx.dewrote in message
news:OL**************@TK2MSFTNGP04.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<stringfor 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<string>.

With IEnumerable they also could return a special enumerator where
calling enumerator.MoveNext() 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.
Jun 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
4
by: CCLeasing | last post by:
I have a text file which consists of lines of data. Each line has units of data seperated by semicolons, like so. AAAA ; some text relating to AAAA ; some more text relating to AAAA BBBB ; some...
16
by: Ron | last post by:
Hello everyone, I've created a functioning ATM program, a bank machine. Now I want to implement usernames and Pins into it. So I have a text file with this info. BILL, 1111 TOM, 2222...
1
by: godofredo | last post by:
Hi! I've a weird problem using ReadAllLines Function. I have a plain text file which has about 6500 lines, each one representing a 3D point. I read the text file and store it in a string array...
4
by: Curious | last post by:
I have a file to which I'll need to at first read until it locates the last line of string. According to content of the last line of string, I'll need to write something to this file right after...
4
by: Jerry Spence1 | last post by:
I'm doing: Dim Contents() As String = System.IO.File.ReadAllLines("C:\MyFile.txt") with upwards of 100,000 lines. This is a brilliantly simple and fast way of creating an array from a text...
2
by: Eric B. | last post by:
I coulda sworn it was possible to overwrite specific lines in a text file without disturbing the rest, or was that in C++? Will a TextWriter object do this? Eric B.
4
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a...
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.