Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core 在F中使用可空引用类型实现C#接口#_.net Core_F#_C# To F#_Nullable Reference Types - Fatal编程技术网

.net core 在F中使用可空引用类型实现C#接口#

.net core 在F中使用可空引用类型实现C#接口#,.net-core,f#,c#-to-f#,nullable-reference-types,.net Core,F#,C# To F#,Nullable Reference Types,我试图通过在C#中转换现有的.NET核心解决方案来学习F#,每次转换一个项目。我目前在C#中有一个接口,具有可为空的引用类型: 公共接口IVehicle{ 公共int GetWheels(); 公共字符串?GetLicensePlate(); } 这个接口在许多依赖于这个接口的其他项目中实现。我正试图转换其中一个,但如果我尝试 类型Car(序列号:字符串)= 将MyProjectInterfaces.IVehicle与 成员:this.GetWheels()=4 成员。GetLicensePl

我试图通过在C#中转换现有的.NET核心解决方案来学习F#,每次转换一个项目。我目前在C#中有一个接口,具有可为空的引用类型:

公共接口IVehicle{
公共int GetWheels();
公共字符串?GetLicensePlate();
}
这个接口在许多依赖于这个接口的其他项目中实现。我正试图转换其中一个,但如果我尝试

类型Car(序列号:字符串)=
将MyProjectInterfaces.IVehicle与
成员:this.GetWheels()=4
成员。GetLicensePlate()=
将LicensePlateService.GetLicensePlate(序列号)与
|Some(x)->System.Nullable(x)
|None->System.Nullable()
我得到一个错误:

此表达式的类型应为“string”,但此处的类型为“Nullable”

这似乎不会影响值类型,因此我假设这与
string
作为引用类型有关


我该怎么解决这个问题?大概我可以重写底层接口以使用F#和选项,但还有其他C#项目实现该接口,我不想一次重写整个解决方案。还是我做的F完全错了?

这是C#8的可空引用和可空值类型之间的混淆,也称为
可空
。如果查看
Nullable
的定义,您会发现:

public struct Nullable<T> where T : struct

将是正确的,尽管不是惯用的替换。

这是C#8的可空引用和可空值类型之间的混淆,也称为
可空
。如果查看
Nullable
的定义,您会发现:

public struct Nullable<T> where T : struct
将是正确的,尽管不是惯用的替换