Extension for convert a stream to string

    0

    1

    lucycodes42

    C# recipes

    In the code above, the System.IO.Stream object is returned that can be used to read data from the stream. Data is read from the beginning of the stream to the position specified, which in this case is the 0th character. The ReadToEnd() method is used to return the data as a string.

    Shortcut: ex_stream_to_string

    public static string ToString(this System.IO.Stream stream)
    {
      stream.Position = 0;
      return new System.IO.StreamReader(stream).ReadToEnd();
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.