相关疑难解决方法(0)

C#和F#cast - 特别是'as'关键字

在C#我可以这样做:

var castValue = inputValue as Type1
Run Code Online (Sandbox Code Playgroud)

在F#中,我可以这样做:

let staticValue = inputValue :> Type1
let dynamicValue = inputValue :?> Type1
Run Code Online (Sandbox Code Playgroud)

但它们都不等同于C#的关键字as.

我想我需要为F#中的等价物做一个匹配表达式

match inputValue with
| :? Type1 as type1Value -> type1Value
| _ -> null
Run Code Online (Sandbox Code Playgroud)

它是否正确?

c# f# c#-to-f#

27
推荐指数
3
解决办法
6201
查看次数

F#相当于C#中的`is`关键字?

我的第一个F#日.如果我有这个:

let cat = Animal()
Run Code Online (Sandbox Code Playgroud)

现在我如何在以后检查cat is Animal

在C#中

bool b = cat is Animal;
Run Code Online (Sandbox Code Playgroud)

在F#?

f# types language-comparisons keyword

13
推荐指数
2
解决办法
1960
查看次数

F#:检查值是否是字符串数组,字符串数组或字符串数​​组

我需要match用来检查值是字符串数组还是字符串.我尝试了一些徒劳的事情

| :? string[] -> ..
| :? string -> ..
| :? array<string[]> -> ..
Run Code Online (Sandbox Code Playgroud)

但是保留.

有帮助吗?

f#

4
推荐指数
1
解决办法
513
查看次数

标签 统计

f# ×3

c# ×1

c#-to-f# ×1

keyword ×1

language-comparisons ×1

types ×1