
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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);
- Related Articles
- PHP Object Serialization
- Python object serialization
- Python object serialization (Pickle)
- Internal Python object serialization (marshal)
- Object Graph in Java Serialization
- Object Serialization with inheritance in Java
- Object Serialization with Inheritance in Java Programming
- How to include Text object's default values in its serialization using FabricJS?
- FabricJS – How to include a Line object's default values in its serialization?
- What is Serialization in Java?
- Serialization and Deserialization in C#
- What is Binary Serialization and Deserialization in C# and how to achieve Binary Serialization in C#?
- What is serialization in C#.NET?
- Difference between Serialization and Externalization in Java
- How transient works with final in Java serialization?

Advertisements