{"id":5116,"date":"2021-06-10T10:55:31","date_gmt":"2021-06-10T09:55:31","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=5116"},"modified":"2023-03-01T16:52:26","modified_gmt":"2023-03-01T15:52:26","slug":"c-simple-stream-conversion","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-simple-stream-conversion\/","title":{"rendered":"C# Simple Stream Conversion"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">\/\/ convert string to stream\nMemoryStream stream = new MemoryStream();\nStreamWriter writer = new StreamWriter( stream );\nwriter.Write( test );\nwriter.Flush();\n\n\/\/ convert stream to string\nstream.Position = 0;\nStreamReader reader = new StreamReader( stream );\nstring text = reader.ReadToEnd();\n\n\npublic static Task&lt;string> ReadStream(Stream stream) \n{\n    stream.Position = 0;\n    using var reader = new StreamReader(stream);\n    return reader.ReadToEndAsync();\n}\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-5116","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/5116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=5116"}],"version-history":[{"count":3,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/5116\/revisions"}],"predecessor-version":[{"id":7456,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/5116\/revisions\/7456"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=5116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=5116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=5116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}