As I needed this some times in the past few days I think maybe someone else could also benefit from this.
1
2
3
4
5
6
7
8
9
| public static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
} |
public static Stream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
1
2
3
4
5
6
7
| public static string GenerateStringFromStream(Stream s)
{
s.Position = 0;
StreamReader reader = new StreamReader(s);
string text = reader.ReadToEnd();
return text;
} |
public static string GenerateStringFromStream(Stream s)
{
s.Position = 0;
StreamReader reader = new StreamReader(s);
string text = reader.ReadToEnd();
return text;
}
Kommentare sind geschlossen.