public abstract WriteInt64 ( long value ) : void | ||
value | long | The Int64 value. |
return | void |
var memoryStream = new MemoryStream(); var bsonWriter = new BsonWriter(memoryStream); bsonWriter.WriteInt64(1234567890L); byte[] binaryData = memoryStream.ToArray();
public class MyObject { public long Id { get; set; } public string Name { get; set; } } var myObject = new MyObject { Id = 9876543210L, Name = "John Doe" }; var memoryStream = new MemoryStream(); var bsonWriter = new BsonWriter(memoryStream); BsonSerializer.Serialize(bsonWriter, myObject); byte[] binaryData = memoryStream.ToArray();This code example creates a new C# class MyObject with a long integer property Id and a string property Name. It then creates an instance of this class with a value of Id as 9876543210L and Name as "John Doe". Finally, it serializes the object to BSON format using the BsonWriter and BsonSerializer.Serialize methods and converts the output to a byte array. The MongoDB.Bson.IO package library provides a low-level BSON serialization API that can be used to write BSON data types as byte streams in C#. The BsonWriter.WriteInt64 method is used to write 64-bit integers to the output stream.
public abstract WriteInt64 ( long value ) : void | ||
value | long | The Int64 value. |
return | void |