views:

23

answers:

2

Hi, I'm going to write System.Data.Linq.Binary value to MemoryStream and perform some manipulations, then re-write new values from MemoryStream to Binary! how to do?

Thanks in advance ;)

A: 

I am not sure exactly about your requirement. The following way might help you achieve your task:

private string ConvertBinaryToString(Binary binaryInformation)
{
         byte[] byteInformation = binary.ToArray();
         string result = "";
         foreach(var bit in byteInformation)
         {
            result+=bit.ToString();
         }
         //Your logic goes here.
}

private Binary ConvertStringToBinary(string text)
{
       //Convert the text into byte array here.
       //Return the byte array back.
}
Siva Gopal
+1  A: 

You can't modify a Binary instance, because it's immutable (the MSDN documentation says: "Represents an immutable block of binary data."). But you can assign a new value to a Binary variable:

Binary binary = ...

// Binary to MemoryStream
MemoryStream stream = new MemoryStream(binary.ToArray());

...

// MemoryStream to binary
binary = stream.ToArray(); // implicit conversion from byte[] to Binary
Thomas Levesque