gpt4 book ai didi

C# 是 nullable decimal 的 nullable int 后代

转载 作者:行者123 更新时间:2023-11-30 19:05:01 25 4
gpt4 key购买 nike

我错误地发现了一些让我吃惊的东西。

我有这个方法

public static string PrintDecimal(decimal? input, string NumberFormat = null){ }

我这样调用这个方法

int? MaxFaltas = 0;
Label.Text = CustomConvert.PrintDecimal(MaxFaltas);

为什么这行得通并且没有编译错误。我正在调用一个方法,该方法被定义为接收 decimal?int?

最佳答案

您刚刚发现了规范中描述为 lifted operators 的内容.

他们让你转换 Nullablt<A>Nullable<B>只要A可以转换为B .

6.4.2 Lifted conversion operators

Given a user-defined conversion operator that converts from a non-nullable value type S to a non-nullable value type T, a lifted conversion operator exists that converts from S? to T?. This lifted conversion operator performs an unwrapping from S? to S followed by the user-defined conversion from S to T followed by a wrapping from T to T?, except that a null valued S? converts directly to a null valued T?.

关于C# 是 nullable decimal 的 nullable int 后代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32386587/

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