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

标签 f# c#-to-f#

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

相关文章:

f# - 如何使用 F# 对 FPGA 进行编程

f# - 清除 F# 中的所有事件处理程序?

entity-framework - 加入 Entity Framework 和 F#

c# - 牛顿分形的 1/4 只画出来了

ide - 非 Visual Studio F# IDE

algorithm - F#:如何计算汉明距离?

.net - 在 F# 中,是否有使用用于相等和排序比较的主键创建记录类型的快捷方式?

f# - 如何将使用 Shell COM 的 C# 代码转换为 F#?

.net - 在 F# 中正确使用带有指针的 P/invoke

wpf - WPF 和 F# 背后的代码