Skip to main content
4 of 7
added 7 characters in body
ΩmegaMan
  • 32.2k
  • 13
  • 110
  • 138

Modernized version of the extension methods for ToStream:

public static Stream ToStream(this string value) => ToStream(value, Encoding.UTF8); public static Stream ToStream(this string value, Encoding encoding) => new MemoryStream(encoding.GetBytes(value ?? string.Empty)); 

It was suggested in a comment of @JoelNet's answer and @Shaun Bowe answer. Because I agree with @Palec's comment.

Nick N.
  • 13.7k
  • 9
  • 62
  • 77