3
4

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 5 years have passed since last update.

C#入門

Posted at
データ型 メモ
decimal 128ビットの数値型。リテラルには最後にmを付ける(10.10mなど)。丸め誤差がない。
char 16ビットの符号なし整数型。Unicode文字を表す。
構造体 struct 構造体名 { }
列挙型 enum 列挙型名 { 列挙値のリスト };
参照型 メモ
クラス class クラス名 { }
インターフェイス public interface インターフェイス名 { }
フォーマット文字列 メモ
Console.WriteLine("{0:#.##}", 10.0/3.0); 出力:3.33
Console.WriteLine("{0:C}", 12345m); 出力:¥12,345
文字列を数値型データに変換する
string str;
try {
	str = Console.ReadLine();
	decimal decimalVal = Decimal.Parse(str);

	str = Console.ReadLine();
	double doubleVal = Double.Parse(str);

	str = Console.ReadLine();
	float floatVal = Single.Parse(str);

	str = Console.ReadLine();
	long longVal = Int64.Parse(str);

	str = Console.ReadLine();
	int intVal = Int32.Parse(str);

	str = Console.ReadLine();
	short shortVal = Int16.Parse(str);

	str = Console.ReadLine();
	ulong ulongVal = UInt64.Parse(str);

	str = Console.ReadLine();
	uint uintVal = UInt32.Parse(str);

	str = Console.ReadLine();
	ushort ushortVal = UInt16.Parse(str);

	str = Console.ReadLine();
	byte byteVal = Byte.Parse(str);

	str = Console.ReadLine();
	sbyte sbyteVal = SByte.Parse(str);
}
catch (FormatException exc) {
}
catch (OverfloatException exc) {
}
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?