using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
int x = 3;
float y;
y = x;
Console.WriteLine(y);
Console.ReadKey();
}
}
}
//输出结果为:3
//c#中的变量如果需要输出就必须初始化,否则不能运行,不输出的可不初始化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
int x;
float y=1.2f;
x = (int)y;//高精度到低精度 需要强制类型转换
Console.WriteLine(x);
Console.ReadKey();
//C#中小数默认为double类型,所以float x=1.2;系统会提示不能将double=隐式转换为float类型,需要加上f后缀创建此类型
}
}
}