I was recently reviewing some samples and I ran across one that made me really appreciate the work we did in BCL in .NET Framework 2.0... it maybe a very trivial thing, but it really improves the code.
The code sample in question looked something like:
if (autoCompleteWordList == null)
List<String> words = new List<string>();
FileStream file = new
StreamReader reader = new StreamReader(file);
while ((word = reader.ReadLine()) != null)
autoCompleteWordList = words.ToArray();
Array.Sort(autoCompleteWordList, new CaseInsensitiveComparer());
I was able to cut the lines of code by more than 1/2 by using the File.ReadAllLines() method added in .NET Framework 2.0
string temp = File.ReadAllLines(Server.MapPath("~/App_Data/words.txt"));
Array.Sort(temp, new CaseInsensitiveComparer());
autoCompleteWordList = temp;
What do you think? What other timesaving gems have you found in .NET Framework 2.0?