You could use the StreamWriter.BaseStream
property as a first argument of the Serialize
method:
binaryFormatter.Serialize(writer.BaseStream, myList);
質問
I am developing a server-client application and I want to serialize a List of strings on the server side and send it to client side.
I want to do the serialization using the BinaryFormatter
class as follows:
List<String> myList = new List<String>();
ceva.Add("A");
ceva.Add("B");
ceva.Add("C!");
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(writer, myList);
My problem is that the writer
streams is of type StreamWriter
and the Serialize
method expects as a first argument an object of type Stream
.
Is there any way I can use my writer of StreamWriter
type the way I try here?
解決
You could use the StreamWriter.BaseStream
property as a first argument of the Serialize
method:
binaryFormatter.Serialize(writer.BaseStream, myList);
他のヒント
You can use like this.
List<String> myList = new List<String>();
ceva.Add("A");
ceva.Add("B");
ceva.Add("C!");
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(writer.BaseStream, myList);