C#中怎么判断数据类型

C#中怎么判断数据类型,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

我们提供的服务有:成都做网站、网站设计、微信公众号开发、网站优化、网站认证、长宁ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的长宁网站制作公司

通过这段代码,可以实现C#判断数据类型

using System;  using System.Collections.Generic;  using System.Text;   public class Test2  {    public void aaB(string a, int b)          {              if(a!=null)        {          Console.WriteLine("The stirng  is " + a + ",  the number is " + b);        }        else        {          Console.WriteLine("error");        }          }    public void checkType(object type)    {          Console.WriteLine("The "+type+" type is {0},", type.GetType());    }    public static void Main()    {      Test2 ts = new Test2();      string a="my name is a";      int b=3662296;      ts.aaB(a,b);  //C#判断数据类型    int   i   =   5;        string k="哈,今天的天氣不錯,我叫string ";      Console.WriteLine("i   is   an   int   ?   {0}" , i.GetType() == typeof(int));       Console.WriteLine("i   is   an   int   ?   {0}" , typeof(int).IsInstanceOfType(i));      Console.WriteLine("k   is   an   int   ?   {0}" , typeof(int).IsInstanceOfType(k));      Console.WriteLine("The type of k is {0},",k.GetType());      ts.checkType(k);      ts.checkType(i);     }   }

关于C#中怎么判断数据类型问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


本文题目:C#中怎么判断数据类型
分享路径:http://bzwzjz.com/article/jjoehs.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站设计 成都网站建设 网站建设公司 成都网站设计 成都网站设计 成都网站建设 达州网站设计 高端网站设计 教育网站设计方案 成都网站设计 自适应网站设计 高端网站设计推广 成都企业网站设计 网站建设 成都网站建设 成都网站设计 重庆网站制作 成都网站建设 成都响应式网站建设公司 成都网站设计 成都网站建设 定制网站建设多少钱