LoginSignup
0
0

C# 変数の型変更

Posted at

型変更の方法

キャスト

数字同士などの似たもの同士を型変換する方法。

double value = 56.23;
int intvalue = (int)value;

Parse

string text = "123";
int value = int.Parse(text);

TryParse

TruParseは返り値がboolになる。
変換できればtrue、できなければfalseを返す。

string text = "123";
int value;
bool result = int.TryParse(text, out value);

Convert

string text = "123456";
int value = Convert.ToInt32(text);
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