Get a TextReader from a Stream?

后端 未结 4 1575
北恋
北恋 2021-02-04 23:21

I\'m trying to read an embedded text file with System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource); but it gives me a Stream

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 23:32

    A StreamReader is a subclass of TextReader, so you will be able to do:

    using(var stream = System.Reflection.Assembly.GetExecutingAssembly().
        GetManifestResourceStream(resource))
    using(var reader = new StreamReader(stream))
    {
        // Use reader.
    }
    

提交回复
热议问题