D
D
Dmitry Gavrilenko2015-01-22 21:16:55
.NET
Dmitry Gavrilenko, 2015-01-22 21:16:55

Is StringWriter inherited from Stream?

XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());

    using(StringWriter textWriter = new StringWriter())
    {
        xmlSerializer.Serialize(textWriter, toSerialize);
        return textWriter.ToString();
    }

StringWriter inherits TextWriter, which in turn inherits MarshalByRefObject.
The Serialize method takes a Stream as its first parameter, but StringWriter does not.
Why does the code work then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2015-01-22
@Maddox

The Serialize method is overloaded and, among other things, can take a TextWriter , from which StringWriter is inherited .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question