成都网站建设设计

将想法与焦点和您一起共享

C#判断数据类型相关代码实例

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

成都创新互联主要从事成都做网站、成都网站制作、成都外贸网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务宁远,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

 
 
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. public class Test2
  5. {
  6.   public void aaB(string a, int b)
  7.         {
  8.             if(a!=null)
  9.       {
  10.         Console.WriteLine("The stirng  is " + a + ",  the number is " + b);
  11.       }
  12.       else
  13.       {
  14.         Console.WriteLine("error");
  15.       }
  16.         }
  17.   public void checkType(object type)
  18.   {
  19.         Console.WriteLine("The "+type+" type is {0},", type.GetType());
  20.   }
  21.   public static void Main()
  22.   {
  23.     Test2 ts = new Test2();
  24.     string a="my name is a";
  25.     int b=3662296;
  26.     ts.aaB(a,b);  //C#判断数据类型
  27.     int   i   =   5;  
  28.     string k="哈,今天的天氣不錯,我叫string ";
  29.     Console.WriteLine("i   is   an   int   ?   {0}" , i.GetType() == typeof(int)); 
  30.     Console.WriteLine("i   is   an   int   ?   {0}" , typeof(int).IsInstanceOfType(i));
  31.     Console.WriteLine("k   is   an   int   ?   {0}" , typeof(int).IsInstanceOfType(k));
  32.     Console.WriteLine("The type of k is {0},",k.GetType());
  33.     ts.checkType(k);
  34.     ts.checkType(i);
  35.    } 
  36. }

C#判断数据类型相关代码实例就介绍到这里。


网站题目:C#判断数据类型相关代码实例
标题网址:http://chengdu.cdxwcx.cn/article/dhoccho.html