怎么编码计算器 [英] how do codeing calculator

查看:189
本文介绍了怎么编码计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class Program 
{ 
    static void Main(string[] args) 
    { 
        Calculator calc = new Calculator(); 
        DiscountDelegate discount = null; 
        if (DateTime.Now.Hour < 12) 
        { 
            discount = new DiscountDelegate(calc.Morning); 
        } 
        else if (DateTime.Now.Hour < 20) 
        { 
            discount = new DiscountDelegate(calc.Afternoon); 
        } 
        else 
        { 
            discount = new DiscountDelegate(calc.Night); 
        } 
        new ShoppingCart().Process(discount); 
    } 
} 
 
class Calculator 
{ 
    public int Morning() 
    { 
        return 5; 
    } 
    public int Afternoon() 
    { 
        return 10; 
    } 
    public int Night() 
    { 
        return 15; 
    } 
} 
 
class ShoppingCart 
{ 
    public void Process(DiscountDelegate discount) 
    { 
        int magicDiscount = discount(); 
        // ... 
    } 
}

推荐答案



你想问什么?我已经在一篇文章中看到了这段代码.我相信这是与代表们一起工作.

干杯

Holger
Hi,

what do you want to ask? I''ve seen this code in an article. I believe it was about working with delegates.

Cheers

Holger


您要编写计算器程序吗?如果是这样,那么此代码对您毫无帮助.您需要提出一个实际的问题,您的问题与您发布的代码无关.如果您需要更改此代码中的计算器"类以执行其他操作,则需要说明您想要执行的操作以及卡在哪里.
Do you want to write a calculator program ? If so, this code can''t help you, obvioulsy. You need to ask an actual question, your question does not relate to the code you posted. If you need to change the ''calculator'' class in this code to do something different, you need to explain what you want it to do, and where you are stuck.


这篇关于怎么编码计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆