使用GetType()进行类型比较和使用typeof()获取类型

来源:互联网 发布:pptv网络电视破解版 编辑:程序博客网 时间:2024/06/05 12:45
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;class Program{    static void Main(string[] args)    {        int name = 123;        if (typeof(string)==name.GetType())        {            Console.WriteLine("是string类型");        }        else        {            Console.WriteLine("不是string类型");        }        Console.ReadKey();    }}   //通过  GetType() 来获取类型声明可以放置变量   //通过  typeof()  来获取类型声明   不可以放置变量

0 0