无法将类型“bool”隐式转换为“int”

初学者112
    private const decimal piece_rate_199 = 0.5M, piece_rate_399 = 0.55M, 
    piece_rate_599 = 0.6M, 
    piece_rate_600= 0.65M;
    private decimal Payrate, TotalPay, AveragePay, WorkerCount, PayEarnedDecimal, PayDecimal;
    private int TotalPieces, QuantityInteger;
    private string MessageString; 
     
    public Form1()
    {
        
        InitializeComponent();
    }
    private decimal FindPayRate()
    {
        QuantityInteger = int.Parse(textNumberPiece.Text);
        switch (QuantityInteger)
        {
            case QuantityInteger >= 600:
                PayDecimal = piece_rate_600;
                break;

            case 400 >= 599:
                PayDecimal = piece_rate_599;
                break;

            case 200 >= 399:
                PayDecimal = piece_rate_399;
                break;

            case 1 >= 199:
                PayDecimal = piece_rate_199;
                break;

        }

请解决这个我完全是一个初学者

丹麦人

@Mureinik 的解决方案是正确的,我只是想添加一种方法来做你想做的,同时仍然使用switch语句。您可以when在 a中使用switch以获得想要的结果:

    switch (QuantityInteger)
    {
        case int n when (n >= 600):
            PayDecimal = piece_rate_600;
            break;

        case int n when (n >= 400 %% n <= 599:
            PayDecimal = piece_rate_599;
            break;

        case int n when (n >= 200 && n <= 399):
            PayDecimal = piece_rate_399;
            break;

        case int n when (n >= 1 && n <= 199:
            PayDecimal = piece_rate_199;
            break;
    }

在我看来,这比使用if-else语句更具可读性

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法将类型'int'隐式转换为'bool'Unity

无法将类型“int”隐式转换为“bool”

“无法将类型'bool []'隐式转换为'object []'”

无法将类型'bool'隐式转换为'float'

无法将类型'ulong'隐式转换为'bool'

Unity无法将类型“ string”隐式转换为“ bool”

无法将类型'string'隐式转换为'bool'[If语句]

无法将类型 'IEnumerable<int> 隐式转换为 'int'

无法将类型int []隐式转换为int?[]

无法将类型'double'隐式转换为'int'。-错误

无法将类型“ double”隐式转换为“ int”

无法将类型'float'隐式转换为'int'

无法将类型隐式转换为int []

无法将类型 *** 隐式转换为 ****

在条件中使用按位运算符-无法将类型'int'隐式转换为'bool'

c# - 如何修复停止“无法将int类型隐式转换为bool”错误代码

如果语句不能隐式将类型转换为bool?

无法将类型'void'隐式转换为'System.Collections.Generic.Dictionary <string,bool>

无法将类型“bool”隐式转换为“Microsoft.AspNetCore.Mvc.ActionResult”

无法将类型'bool'隐式转换为'System.Threading.Tasks.Task'

Unity3d“无法将类型“ void”隐式转换为“ bool””

实体框架错误无法隐式将类型“bool”转换为“string”

如何解决错误:无法将类型“long”隐式转换为“bool”?

我的代码返回无法将 int 隐式转换为 bool

当似乎不涉及“ long”类型时,无法将“ long”类型隐式转换为“ int”

数组出现问题(无法将类型'int'隐式转换为'int []')

C# - 无法将类型“int”隐式转换为“int[][]” - CodeFights

webservice无法构建-“无法将类型'string'隐式转换为'int'”

无法将int隐式转换为int []