我有字符串对象.我需要将此数据传递给另一个XYZ类型的对象.但是XYZ类型的这个对象只采用System.IO.Stream.那么如何将字符串数据转换为流,以便XYZ类型的对象可以使用此字符串数据?
Ada*_*son 26
您必须选择一个文本编码来将字符串转换为字节数组,然后使用a MemoryStream来调用您的函数.例如:
using(System.IO.MemoryStream ms = new System.IO.MemoryStream(
System.Text.Encoding.UTF16.GetBytes(yourString)))
{
XYZ(ms);
}
Run Code Online (Sandbox Code Playgroud)
您可以将其更改UTF16为您要用于传递字符串的任何编码.
| 归档时间: |
|
| 查看次数: |
12339 次 |
| 最近记录: |