C#判断数据类型相关代码实例
通过这段代码,可以实现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#创建Windows服务学习的一点体会
- C#Windows服务程序之添加安装程序图解
- C#Windows服务程序开发实例浅析
- C#Windows服务程序开发浅析
- C#Windows服务程序的快速开发
版权声明:
作者:后浪云
链接:https://www.idc.net/help/405211/
文章版权归作者所有,未经允许请勿转载。
THE END