Serialization and deserialization of an int matrix c#

Viewed 1802

I'm using a c# WCF service and I need to return a int[,] to the client in one of my method. The problem is multidimensional arrays are not supported by WCF so I think my only option is returning a byte array in this way:

    public byte[] DistanceMatrix()
    {
        int[,] matrix;

        //DOING THINGS HERE

        IFormatter formatter = new BinaryFormatter();
        var ms = new MemoryStream();
        formatter.Serialize(ms, matrix);

        return ms.ToArray();
    }

But I don't know how to deserialize the byte[] back to an int[,].

1 Answers
Related