0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C#:四則演算

Posted at

四則演算記号

  • 足し算
    • A + B
  • 引き算
    • A - B
  • 掛け算
    • A * B
  • 割り算
    • A / B
  • あまりの計算
    • A % B

変数に代入して計算する

  • int x = 1; int y = 2; int z = x + y;

  • 文字列の計算

    • string s = "野球" string h = "部" string g = s + h; //自民党
    • 文字列 + 数字の場合は全て文字列になる
  • 代入演算

    • A += B; → A = A + B;
  • インクリメント、デクリメント

    • a++, a--, ++a, --a
    • 変数の前か後につけて変数の値を1増やす、1減らすといった働きをする
四則演算.cs

//[四則演算]変数を使用して計算
int a = 10;
int b = 3;

//足し算
a + b; // 13
//引き算
a - b; // 7
//掛け算
a * b; // 30
//割り算
a / b; // 3
//あまりの計算
a % b; // 1

//[テキストの計算]
Debug.Log("答え:" + a); // 答え:10 10も文字列として考える


//[代入演算子]
a *= b; //30
a *= 2; //20
string s = "Hello";

//インクリメント、デクリメント
a++; //9
a--; //9
++a; 
--a;

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?