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

开发 后端
这是一篇C#判断数据类型相关代码实例,通过这段代码,可以实现C#判断数据类型,希望本文对大家有所帮助。

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

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

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

【编辑推荐】

  1. C#创建Windows服务学习的一点体会
  2. C#Windows服务程序之添加安装程序图解
  3. C#Windows服务程序开发实例浅析
  4. C#Windows服务程序开发浅析
  5. C#Windows服务程序的快速开发
责任编辑:彭凡 来源: aixq.com
相关推荐

2009-09-04 10:16:30

C#数据类型

2009-08-27 15:47:00

C#数据类型string

2011-06-08 13:35:18

C#数据类型

2009-09-07 10:48:53

C#数据类型

2009-09-11 12:00:33

C#预定义数据类型

2009-09-01 16:35:55

C#操作String数

2009-08-12 16:26:27

C#数据类型转换

2009-08-18 10:47:40

C#枚举类型

2009-08-18 10:17:25

C#枚举类型

2009-08-07 15:38:15

精通C#数据库编程

2009-08-13 15:19:17

C#数据类型

2010-08-26 17:16:19

Infobright

2009-09-02 17:12:06

C#关机代码

2009-08-14 11:15:45

C#基本数据类型

2009-09-02 14:06:14

C#文件传送

2011-08-25 13:31:08

SQL Server批量修改字段存储过程

2010-04-23 14:08:11

Oracle数据类型

2009-08-12 16:01:32

C#动态改变数据

2024-03-14 11:54:37

C++数据类型

2009-08-18 10:41:38

C#枚举类型
点赞
收藏

51CTO技术栈公众号