I have two streams that i want to combine into one stream. The first stream is user-defined stringStream class that inherits from System.IO.Stream class and the second stream is a networkStream , I created an array of Stream with stores those two streams and pass it to a user-defined class combinedStream constructor as parameter. Below are the lines of code
StringStream stringStream = new StringStream("test string");
Stream[] streamArray = new Stream[2];
streamArray[0] = stringStream;
streamArray[1] = nsStream;//NetworkStream instance parameter
CombinedStream combinedStream = new CombinedStream(streamArray);
this.nsStream = (NetworkStream)combinedStream;
This the error i got : “Cannot convert CombinedStream to NetworkStream”
What could be the reason?
Fairly simply, because
CombinedStream(which is presumably your own class) is not aNetworkStream. I wouldn’t expect it to be.The big question is why
nsStreamis meant to be aNetworkStreamanyway. Can you change the type so it’s justStreaminstead? That should be fine unless you’re using anyNetworkStream-specific methods… and if you’re doing that, then what would you expect to happen when those methods were called on aCombinedStream?