It’s kinda odd - but there’s no standard way to copy between streams in the .net framework. Coming from a Delphi background, I’m used to being able to easily copy information from one stream to another easily.

Why? The common ancestor to all Delphi streams (TStream) includes a method that does exactly that. Here is the declaration:

function CopyFrom(Source: TStream; Count: Int64): Int64;

This allows you to copy a specified number of bytes from the current position in one stream into a target stream.

The .Net framework doesn’t have this - meaning that whenever there is a need to copy information from one stream to another (a common enough occurrence), the developer needs to roll their own.

Admittedly, the function is easy enough to implement (there is even an example buried in the help file, if you can but find it).

It just seems an oddly fundamental thing to have left out - isn’t the whole idea of a framework to supply the common stuff so you can concentrate on the things unique to your application?

Update April 2014: It took several years, but in .NET 4.0 Microsoft introduced a CopyTo method on the Stream base class. Yay!

Comments

blog comments powered by Disqus
Next Post
Wiki for the win  01 Dec 2003
Related Posts
Types behaving badly  14 Apr 2018
Implementing Value Equality  07 Apr 2018
Implementing Entity Equality  31 Mar 2018
Equality and GetHashCode  24 Mar 2018
Types of Equality  10 Mar 2018
Why is Equality important in .NET?  03 Mar 2018
Invalid Build Configuration: Debug|BNB  14 May 2011
Intersect and Except  24 Jul 2008
Streams in .NET  26 Dec 2003
Bitmap cloning in .NET  11 Dec 2003
Archives
November 2003
2003