C#反序列化
在C#编程中,反序列化是序列化的反向过程。这意味着您可以从字节流中读取对象。这里,无涯教程将使用BinaryFormatter.Deserialize(stream)方法对流进行反序列化。

C#反序列化示例
让无涯教程看看C#中的反序列化的简单示例。
using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; [Serializable] class Student { public int rollno; public string name; public Student(int rollno, string name) { this.rollno = rollno; this.name = name; } } public class DeserializeExample { public static void Main(string[] args) { FileStream stream = new FileStream("e:\\sss.txt", FileMode.OpenOrCreate); BinaryFormatter formatter=new BinaryFormatter(); Student s=(Student)formatter.Deserialize(stream); Console.WriteLine("Rollno: " + s.rollno); Console.WriteLine("Name: " + s.name); stream.Close(); } }
输出:
Rollno: 101 Name: sonoo
祝学习愉快! (发现内容有误?请选中要编辑的内容 -> 右键 -> 修改 -> 提交!帮助我们改进教程质量)
精选教程推荐
👇 以下精选教程可能对您有帮助,拓展您的技术视野
暂无学习笔记,成为第一个分享的人吧!
您的笔记将帮助成千上万的学习者