Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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# 如何使用txt文件作为命令行参数?_C#_Console_Command Line Arguments - Fatal编程技术网

C# 如何使用txt文件作为命令行参数?

C# 如何使用txt文件作为命令行参数?,c#,console,command-line-arguments,C#,Console,Command Line Arguments,我有一个.txt文件,如下所示: 6 4 1 2 2 3 3 4 4 5 1 2 4 5 如何将其用作C中的命令行参数?您可以在命令行中接受文件名和路径,并在应用程序中打开文件,逐行读取并处理所有行。如果您打算为程序数据program.exe右键单击项目文件>从关联菜单中选择属性。这将打开项目的“属性”窗口。现在转到右窗格中的调试选项卡>转到开始选项部分。将完整文件路径放入命令行参数文本框中,如下所示: < "D:\Rasik\input01.txt" < "D:\Rasik\in

我有一个.txt文件,如下所示: 6 4 1 2 2 3 3 4 4 5 1 2 4 5


如何将其用作C中的命令行参数?

您可以在命令行中接受文件名和路径,并在应用程序中打开文件,逐行读取并处理所有行。

如果您打算为程序数据program.exe 或者,如果希望程序运行program.exe data.txt,请从

void Main(string[] args)
{
    File.ReadLines(args[0])
}
转到解决方案资源管理器>右键单击项目文件>从关联菜单中选择属性。这将打开项目的“属性”窗口。现在转到右窗格中的调试选项卡>转到开始选项部分。将完整文件路径放入命令行参数文本框中,如下所示:

< "D:\Rasik\input01.txt"
< "D:\Rasik\input01.txt"
class Program
{        
    static void Main(string[] args)
    {
        var textInFirstLineOfFile = Console.ReadLine();
    }
}