「C#入門」explicitで明示的型変換を実装するサンプル
書式
int 変数名A = (int)double型変数名B
使用例
using System;
namespace TestDemo
{
class Program
{
static void Main(string[] args)
{
double cftDb = 5.36;
int intRes = (int) cftDb; // double型をint型に変換
Console.WriteLine(cftDb);
Console.WriteLine(intRes);
}
}
}
using System;
namespace TestDemo
{
class Program
{
static void Main(string[] args)
{
double cftDb = 5.36;
int intRes = (int) cftDb; // double型をint型に変換
Console.WriteLine(cftDb);
Console.WriteLine(intRes);
}
}
}
using System; namespace TestDemo { class Program { static void Main(string[] args) { double cftDb = 5.36; int intRes = (int) cftDb; // double型をint型に変換 Console.WriteLine(cftDb); Console.WriteLine(intRes); } } }
実行結果
5.36
5