Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将列表中的1个元素写入一个字符串,处理它并重复此操作,直到I';我看完了名单_C#_String_List - Fatal编程技术网

C# 将列表中的1个元素写入一个字符串,处理它并重复此操作,直到I';我看完了名单

C# 将列表中的1个元素写入一个字符串,处理它并重复此操作,直到I';我看完了名单,c#,string,list,C#,String,List,我想从列表中提取一个元素,将其交给一个使用它的方法,然后从列表中提取下一个元素,直到我看完整个列表。问题是它仍然在“_rawText=[here]”之后的部分加下划线,我不知道怎么了。它说有无效的论点。到目前为止,我已经做到了: string _rawText = ""; List<string> _fileNameList = new List<string>(); for (int i = 0; i < _fil

我想从列表中提取一个元素,将其交给一个使用它的方法,然后从列表中提取下一个元素,直到我看完整个列表。问题是它仍然在“_rawText=[here]”之后的部分加下划线,我不知道怎么了。它说有无效的论点。到目前为止,我已经做到了:

        string _rawText = "";
        List<string> _fileNameList = new List<string>();

        for (int i = 0; i < _fileNameList.Count; i++)
            {
                Console.WriteLine("\nDocument " + (i+1) +" of " + _fileNameList.Count + "\n");

                _rawText = ReadDocument(_fileNameList[i].ToString());

                CheckDocument(_rawText);

                AnalyzeResult();

                PrintResult();
            }

public string ReadDocument(List<string> _fileNameList)
        {
            if (File.Exists(_rawText))
            {
                return File.ReadAllText(_rawText);
            }
            else
            {
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nKeine Datei gefunden!\n");
                Console.ResetColor();

                Console.WriteLine("Soll eine Textdatei unter folgendem Pfad erstellt werden? < j / n >");
                Console.WriteLine("Pfad: \"" + _rawText + "\"");

                string createFile = "";

                do
                {
                    createFile = Console.ReadLine().ToUpper().Trim();
                    switch (createFile)
                    {
                        case "J":
                            Console.Write("Datei wird erstellt...");

                            File.Create(_rawText());

                            if (!File.Exists(_rawText))
                            {
                                Console.WriteLine("Datei konnte nicht ertellt werden.");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("\nDatei wurde erfolgreich erstellt.");
                                Console.BackgroundColor = ConsoleColor.DarkYellow;
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("Hinweis:");
                                Console.ResetColor();
                                Console.WriteLine("Bitte den zu überprüfenden Text in die Datei schreiben und das Programm erneut starten.");
                                break;
                            }
                        case "N":
                            Console.WriteLine("Programm wird beendet . . .");
                            Thread.Sleep(350);
                            Environment.Exit(0);
                            break;
                        case "LOL":
                            while (true)
                                Console.Write("LOL---");
                            break;
                        default:
                            Console.WriteLine("");
                            Console.BackgroundColor = ConsoleColor.Gray;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.WriteLine("Falsche Eigabe. Bitte gültigen Buchstaben eingeben. < j / n >");
                            Console.ResetColor();
                            Console.WriteLine("");
                            break;
                    }
                } while (createFile != "J" && createFile != "N");

                return string.Empty;
            }
        }
string_rawText=”“;
列表_fileNameList=新列表();
对于(int i=0;i<\u fileNameList.Count;i++)
{
Console.WriteLine(“+_fileNameList.Count+”\n“\n文档“+(i+1)+”);
_rawText=ReadDocument(_fileNameList[i].ToString());
检查文件(_rawText);
AnalyzerResult();
PrintResult();
}
公共字符串ReadDocument(列表\u文件名列表)
{
if(File.Exists(_rawText))
{
返回文件.ReadAllText(_rawText);
}
其他的
{
Console.BackgroundColor=ConsoleColor.DarkRed;
Console.ForegroundColor=ConsoleColor.White;
Console.WriteLine(“\nKeine Datei gefunden!\n”);
Console.ResetColor();
Console.WriteLine(“将文本数据存储在文件夹Pfad-erstellt-werden?”);
Console.WriteLine(“Pfad:\”“+\u rawText+”\”);
字符串createFile=“”;
做
{
createFile=Console.ReadLine().ToUpper().Trim();
开关(创建文件)
{
案例“J”:
控制台。写入(“Datei wird Erstellet…”);
创建(_rawText());
如果(!File.Exists(_rawText))
{
Console.WriteLine(“Datei konnte nicht ertellt werden”);
打破
}
其他的
{
Console.WriteLine(“\nDai wurde erfolgreich Erstellet.”);
Console.BackgroundColor=ConsoleColor.DarkYellow;
Console.ForegroundColor=ConsoleColor.White;
控制台。WriteLine(“Hinweis:”);
Console.ResetColor();
Console.WriteLine(“在Datei schreiben and das Programm Ernut starten中的bite den zuüberprüfenden文本”);
打破
}
案例“N”:
Console.WriteLine(“程序向导…”);
睡眠(350);
环境。退出(0);
打破
案例“LOL”:
while(true)
Console.Write(“LOL--”);
打破
违约:
控制台。写线(“”);
Console.BackgroundColor=ConsoleColor.Gray;
Console.ForegroundColor=ConsoleColor.Black;
Console.WriteLine(“Falsche Eigabe.Bite gültigen Buchstaben eingeben.”);
Console.ResetColor();
控制台。写线(“”);
打破
}
}而(createFile!=“J”&&createFile!=“N”);
返回字符串。空;
}
}

问题是ReadDocument接受一个字符串列表,而您只传入一个字符串。但该方法无论如何都不使用该参数。它使用的是未在方法中定义的_rawText。你好像有很多问题。但最初的问题是在需要
列表时传递字符串

您的
ReadDocument()
方法需要一个完整的列表作为参数,但您传递的是一个字符串。根据循环中的代码,您应该更改
ReadDocument()
的签名以接收字符串:

public string ReadDocument(string fileName)
{
    if (File.Exists(fileName))
    {
        return File.ReadAllText(fileName);
    }
    else
    {
       //...
    }
}

你的问题是什么?看起来你已经知道该怎么做了?您已经创建了一个for循环,并且正在对其进行迭代。你的问题是什么?什么是你不想让它做的?对不起,我应该提到的。问题是它仍然在“_rawText=[here]”之后的部分加下划线,我不知道怎么了。它说有无效的参数。那么ReadDocument的签名是什么呢?您不需要.ToString(),它已经是一个字符串了。您能告诉我程序在我的ReadDocument方法中需要哪个值吗<代码>控制台。编写(“Datei wird Erstelt…”);创建(_fileNameList[HERE]);如果(!File.Exists(_fileNameList))