DQDQbJ%Pyub'^^'biy@Ppiy|iy^']'^]aAabeBEfXCC| 5784558VZYBW

File.ReadAllLines` returns an array. This array contains a string for each line in the file specified. We use this method. We then look inside its .NET Framework implementation to see how it works. It is found in the System.IO namespace.`Example.` This example program specifies a file on the disk. To have it run correctly, change the filename to one that exists. ReadAllLines gets a string array from the file. The string array returned can be used as any other string array. `Then: `We can use "foreach" or "for" to loop over the file's data in a clean and intuitive way.`This program reads in a file, counts its lines, and counts all chars in each line.`Implementation.` The File.ReadAllLines method is not a low-level implementation. Instead, it uses a List and the StreamReader type, and then ToArray, to return the array. This is inefficient if you want to put a file into a List.`If you need` to optimize a File.ReadAllLines call, you could estimate the capacity of the List in its constructor, which would reduce resizes. You could also avoid ToArray if you want to keep the List. `List `list`StreamReader `streamreader`ToArray `toarray`Capacity `capacity`Summary.` We looked at the File.ReadAllLines method in the .NET Framework version 4.0. This is a convenience method that uses StreamReader and List internally. It can be useful in quick programs where you simply want all the lines in a file. `But: `If you need to save memory, reading in the lines one-by-one and processing them as you read them would be effective.

567 66; 66.IO66A { 565{ 5576[]7 lines67File.6AllLines7(7"C:\\rearrange.txt"7)65567"L6: {0}"7, lines.L6); 5567"First: {0}"7, lines[0])6556count60; 55767 (6 line6lines) 55{ 555count++; 55} 556c60; 55767 (6i60; i < lines.L6; i++) 55{ 555c++; 55} 5567"6: {0}"7, count); 5567"C: {0}"7, c); 5} } 7 L6: 430 First: /_1=D1 6: 430 C: 4307

!7calls File.ReadAllLines