C#C
C#12mo ago
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");
Was this page helpful?