gpt4 book ai didi

f# - Uri().AbsolutePath "Unexpected symbol ' .' in binding."F#中的错误表达式

转载 作者:行者123 更新时间:2023-12-02 01:42:28 25 4
gpt4 key购买 nike

我在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com