© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
217 replies
Tracer

Serialize HashSet into a binary file

Hello. I want to serialize a hashset into a binary file.
I tried using BinaryFormatter but its obsolete. I dont want to save it as xml or json but as pure bytes.
How could I do it?
enum Test {
  A = 1,
  B = 2,
  C = 3
}

HashSet<Test> set = new HashSet<Test>();

set.Add(Test.A);
set.Add(Test.C);
set.Add(Test.B);

// How to do that?
Serialize(set, "myfile.bin");
enum Test {
  A = 1,
  B = 2,
  C = 3
}

HashSet<Test> set = new HashSet<Test>();

set.Add(Test.A);
set.Add(Test.C);
set.Add(Test.B);

// How to do that?
Serialize(set, "myfile.bin");
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Parsing a binary file into a byte array
C#CC# / help
3y ago
Convert a Binary string to a file
C#CC# / help
2y ago
Design Hashset
C#CC# / help
2y ago