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://www.hxwzsj.com/article/jjoehs.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都定制网站建设 成都营销网站制作 网站设计 成都网站设计 成都网站设计 定制级高端网站建设 成都网站建设 手机网站建设 成都网站建设公司 网站建设费用 手机网站设计 成都网站设计公司 成都响应式网站建设 响应式网站建设 成都网站设计 网站制作报价 成都网站建设 四川成都网站制作 成都营销网站建设 网站制作 重庆企业网站建设 外贸网站建设