里程(L/km) 费用(元)
35<L≤200 106
200<L≤400 151
400<L≤600 227
600<L≤800 275
800<L≤1000 376
1000<L≤1200 416
1200<L≤1400 455
1400<L≤1600 496
1600<L≤1800 534
1800<L≤2000 568
2000<L≤2200 601
2200<L≤2400 688
2400<L≤2600 724
2600<L≤2800 757
2800<L≤3000 784
3000<L≤3200 868
3200<L≤3400 903
3400<L≤3600 928
3600<L≤3800 964
3800<L≤4000 1042
4000<L≤4200 1071
4200<L≤4400 1095
L >4400km 时,每 增加 200km 增加 73我要怎么根据录入的里程数计算出费用,有没必要用设计模式来代替if else/case,如果要,用那个设计模式,或者哪些模式结合起来,怎么用,谢谢!
35<L≤200 106
200<L≤400 151
400<L≤600 227
600<L≤800 275
800<L≤1000 376
1000<L≤1200 416
1200<L≤1400 455
1400<L≤1600 496
1600<L≤1800 534
1800<L≤2000 568
2000<L≤2200 601
2200<L≤2400 688
2400<L≤2600 724
2600<L≤2800 757
2800<L≤3000 784
3000<L≤3200 868
3200<L≤3400 903
3400<L≤3600 928
3600<L≤3800 964
3800<L≤4000 1042
4000<L≤4200 1071
4200<L≤4400 1095
L >4400km 时,每 增加 200km 增加 73我要怎么根据录入的里程数计算出费用,有没必要用设计模式来代替if else/case,如果要,用那个设计模式,或者哪些模式结合起来,怎么用,谢谢!
{
public int 最低里程;
public int 最高里程;
public decimal 费用;
}然后在程序启动时初始化一个 List<费用对照Item>列表,程序中查表来计算费用。如果这也叫做模式的话,就叫做“简单分析业务逻辑”模式吧。
{
public int MinValue {get;set;}
public int MaxValue {get;set;}
public decimal Cost {get;set;}
public bool IsMatch(int L) { return MinValue < L && MaxValue >= L; }
}List<Rule> rules;
...
var rule = rules.SingleOrDefault(r => r.IsMatch(L));