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)
        {
            decimal i = 4;
            int a = 5;
            //强制转换只能在值类型对值类型中转换

            decimal s = (int)i / a; //在变量前面加括号数据类型可以强制转换
            
            //从值类型转换为引用类型是显示转换

            string ss = i.ToString(); //i会变成一个字符串型的结果(显式转换)
            //从引用类型转换为值类型是隐式转换
            string s1 = "3.68";
            double dd = Convert.ToDouble(s1);
            //double dd = double.Parse(s1);

            Console.WriteLine(s1);
            Console.ReadLine();
        }
    }
}

原文地址:https://www.cnblogs.com/2041388565m/p/4154635.html