编程语言
首页 > 编程语言> > C#表达式学习笔记

C#表达式学习笔记

作者:互联网

案例一:

买西瓜

*超市西瓜价格是1.9元/斤

*老婆下班买了6斤西瓜

*此时正逢双十一,超市购买商品满10元优惠7.5折

*问此时老婆买西瓜花了多少钱

看代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      double price = 1.9;//单价;
      int count = 6;//数量;
      double discount = 0.75;//折扣;
      double sum;//存放总的价钱;
      //计算折前价;
      sum = price * count;
      //判断折前价是否大于折扣价10元;
      if (sum > 10)
      {
        //超过10元打折;
        sum = sum * discount;//打折存放折后价(复合赋值);
      }
      MessageBox.Show(sum.ToString());//信息栏显示价钱;

    }
  }
}

计算结果

 

标签:10,C#,double,sum,System,笔记,Form1,using,表达式
来源: https://www.cnblogs.com/BlogRigisteraspx/p/15977666.html