- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# object serialization
For object serialization, you need to refer the below code. Here, we have use the BinaryFormatter.Serialize (stream, reference) method to serialize our sample object.
We have set a constructor here −
public Employee(int id, string name, int salary) { this.id = id; this.name = name; this.salary = salary; }
Now set the file stream −
FileStream fStream = new FileStream("d:\
ew.txt", FileMode.OpenOrCreate); BinaryFormatter bFormat = new BinaryFormatter();
An object of the Employee class −
Employee emp = new Employee(001, "Jim", 30000); bFormat.Serialize(fStream, emp);
Advertisements