我在C#中有这样一条语句:
private static string LogPath
{
get
{
string filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
return Path.GetDirectoryName(filePath) + "/cube_solver_log.txt";
}
}
当我尝试用 F# 编写时;
static member LogPath() =
let filePath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"
我遇到了一个异常:
Unexpected symbol '.' in binding. Expected incomplete structured construct at or before this point or other token.
因为在 F# 中,我不知道为什么,系统库不接受我的代码中的 .AbsolutePath
。
我该如何解决这个问题?
最佳答案
您需要在 new
表达式两边添加方括号:
static member LogPath() =
let filePath = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath
Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"
事实上 new
关键字是可选的,因此您可以:
let LogPath() =
let filePath = Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath
Path.GetDirectoryName(filePath) + "/cube_solver_log.txt"
关于f# - Uri().AbsolutePath "Unexpected symbol ' .' in binding."F#中的错误表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27733538/