C#中的类型转换

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            int val = 97;
            Console.WriteLine("{0}",val); // 97

            bool boolVal = Convert.ToBoolean(val);
            Console.WriteLine("{0}", boolVal); // true

            byte byteVal = Convert.ToByte(val);
            Console.WriteLine("{0}", byteVal); // 97

            char charVal = Convert.ToChar(val);
            Console.WriteLine("{0}",charVal); // a

            decimal decimalVal = Convert.ToDecimal(val);
            Console.WriteLine("{0}", decimalVal); // 97

            double doubleVal = Convert.ToDouble(val);
            Console.WriteLine("{0}", doubleVal); // 97

            short shortVal = Convert.ToInt16(val);
            Console.WriteLine("{0}", shortVal); // 97

            int intVal = Convert.ToInt32(val);
            Console.WriteLine("{0}", intVal); // 97

            long longVal = Convert.ToInt64(val);
            Console.WriteLine("{0}", longVal); // 97

            sbyte sbyteVal = Convert.ToSByte(val);
            Console.WriteLine("{0}", sbyteVal); // 97

            float floatVal = Convert.ToSingle(val);
            Console.WriteLine("{0}", floatVal); // 97

            string stringVal = Convert.ToString(val);
            Console.WriteLine("{0}", stringVal); // 97

            ushort ushortVal = Convert.ToUInt16(val);
            Console.WriteLine("{0}", ushortVal); // 97

            uint uintVal = Convert.ToUInt32(val);
            Console.WriteLine("{0}", uintVal); // 97

            ulong ulongVal = Convert.ToUInt64(val);
            Console.WriteLine("{0}", ulongVal); // 97


            Console.ReadKey();
        }
    }
}

posted @ 2017-04-18 16:09  TBHacker  阅读(373)  评论(0编辑  收藏  举报