Convert String to Stream and stream to string

using System;
using System.IO;
using System.Text;
 
namespace streamDemo
{
class Program
{
static void Main( string[] args )
{
string str= "I love my India";
 
/*convert string to stream*/
byte[] byteArray = Encoding.ASCII.GetBytes( str);
MemoryStream stream = new MemoryStream( byteArray );
 
/* convert stream to string*/
StreamReader reader = new StreamReader( stream );
string text = reader.ReadToEnd();
 
Console.WriteLine(str);
Console.ReadLine();
}
}
}
Ebook Download
View all
Learn
View all