StreamReader doesn't take string?

江枫思渺然 提交于 2019-12-20 07:27:12

问题


I'm trying to read a file with a StreamReader, but I get an error for using path

Argument 1: cannot convert from 'string' to System.IO.Stream

even though it's clear from the documentation, that you should be able to use a string.
What am I missing here?

public MyClass Load(String path)
{
    try
    {
        // exception in this line, `path` is underlined with red
        using (StreamReader reader = new StreamReader(path)) 
        {
            String line = reader.ReadLine();
// ... etc

回答1:


I can't tell if you got your answer or not but the proper syntax for UWP is below:

using (var sr = new StreamReader(new FileStream(filenamestring, FileMode.Open)))


来源:https://stackoverflow.com/questions/40928153/streamreader-doesnt-take-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!