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#:値の種類と変数

Last updated at Posted at 2021-11-04

値の種類

  • 値の型 4種類のみ
    • 整数
      • 基本的にはintを使用
    • 実数
      • 基本的にfloatを使用
      • 使用する際には数字の後に f をつける 例)24.5f
    • 文字列
      • 基本的にStringを使用
      • 使用する際にはダブルクウォーテーションで囲む 例)"日本語"
    • 真偽値
      • true, falseを使用
  • 変数の利用範囲
    • 変数は、その変数の宣言をした構文の中でだけ使える。構文を抜けて外に出ると使えない。
    • 変数宣言が書いてある{} 記号の内部でのみ使える。ということ。

 変数

  • 変数を使用するには値と変数の型が一緒で無くてはならない
  • 変数に値を入れることを代入
  • 変数に使える値は半角英数字とアンダースコア( _ )のみ
変数.cs

//[変数の宣言]
//型名 = 変数名;
//型名 = 変数名, 変数名, 変数名....;
int x; 
string s;

//[変数への代入]
//変数 = 値;
x = 100;
s = "Hello";

//[宣言と代入]
int x = 100;
string s = "Hello";

//変数の名前
name; //OK
first_name; //OK
last-name; //NG ハイフンがだめ

0
0
2

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?