码迷,mamicode.com
首页 > Windows程序 > 详细

C# 之 流和字符串之间的相互转换

时间:2015-09-07 10:47:17      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.IO;
using System.Text;
namespace CSharpConvertString2Stream
{    
     class Program    
     {               
         static void Main( string[] args )
         {            
            string str = "This is the test string.";         //convert string to stream            
            byte[] array = Encoding.ASCII.GetBytes(str);            
            MemoryStream stream = new MemoryStream(array);   //convert stream to string      
            StreamReader reader = new StreamReader(stream);
            string text = reader.ReadToEnd();
            Console.WriteLine(text); 
            Console.ReadLine(); 
        }  
    }
}

 

C# 之 流和字符串之间的相互转换

标签:

原文地址:http://www.cnblogs.com/xinaixia/p/4788077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!