ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToStream

Converts a String to a MemoryStream

Source

public System.IO.MemoryStream ToStream(this string Source)
{
    byte[] Bytes = System.Text.Encoding.ASCII.GetBytes(Source);
    return new System.IO.MemoryStream(Bytes);
}

Example

stream MyStream = "Fred".ToStream();

Author: Rory Becker

Submitted on: 7 feb. 2011

Language: C#

Type: System.String

Views: 6313