The .NET runtime has so many features it is difficult to keep track. Just the other night, I need to write a byte[] to a file. I started out with something like this:

using (FileStream stream = newFileStream("myfile", FileMode.CreateNew))
    stream.Write(buffer, 0, buffer.Length);

Not bad but it is a little tedious. Then I discovered quite by accident that .NET 2.0 added helper methods to the System.File class including System.File.WriteAllBytes.

Other “helper” methods include ReadAllBytes, ReadAllLines, ReadAllText, WriteAllLines, WriteAllText and AppendAllText. These methods are not hard to write as evidenced above, but they sure are handy none-the-less.

So now the example above becomes:

File.WriteAllBytes("myfile", buffer);
← newer older →
.Net, Technology, Life, Whatever

Recent Posts

Tweetz Release 1.2.4 - Screen Off Detection
Tweetz Desktop Support for 280 Characters
Quick Tip - Clear ReSharper's Cache to Fix False Errors
Quick Tip - Refined GitHub
Vertical Layout for HTML Tables
Visual Studio 2017 Installer Quick Tip
VSColorOutput for VS 2017 Released
More... (1079)