简体   繁体   English

用F#项目打开文件

[英]Open file with F# project

I would like to read a file in an F# console app when I select the file to be opened with the app, like in this code for C#. 当我选择要使用应用程序打开的文件时,我想在F#控制台应用程序中读取文件,就像在此C#代码中一样
The main module does not seem to take arguments, is there any method I can do this? 主模块似乎没有参数,是否有任何方法可以做到这一点?
Thanks! 谢谢!

You can create an F# console application with an explicit main function by having the following as the last function in the last file of your project: 您可以通过将以下内容作为项目的最后一个文件中的最后一个函数来创建具有显式main函数的F#控制台应用程序:

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    0

The argv parameter is the array of command line arguments. argv参数是命令行参数的数组。 This sample just prints it so that you can see what parameters your application gets. 此示例只是打印它,以便您可以查看应用程序获取的参数。

Alternatively, you can also get the command line arguments using the GetCommandLineArgs method provided by the System.Environment object: 或者,您也可以使用System.Environment对象提供的GetCommandLineArgs方法获取命令行参数:

System.Environment.GetCommandLineArgs()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM