运算

运算的意义

  • 编程中每一个行为都可以用多个运算来表示。

    // 蜗牛往上爬了3米
    int position = 0; // position表示蜗牛当前的位置。
    position = position + 3; // 蜗牛往上爬了3米
    
    // 攻击
    int mp = 100; // 玩家当前的魔法值。
    int monsterHp = 100; // 怪物当前的血量
    
    // 玩家发起攻击
    mp = mp - 30; // 攻击时用掉了30的MP
    monsterHp = monsterHp - 50; // 打掉了怪物50点血
    

运算符优先级

  • 可以使用()控制运算的顺序。
    int result = (1+2)* (3+4); // 3 * 7
    Console.WriteLine(result); // 输出:21
    

results matching ""

    No results matching ""