不用正则的:- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- namespace 输出数字
- {
- class Program
- {
- static void Main(string[] args)
- {
- ArrayList al = GetArrayList();
- //int item=1;
- //Console.WriteLine(item.GetType());
- foreach (object item in al)
- {
- if (item.GetType().ToString()== "System.Int32") //加一个判断类型是否为int32,
- {
- Console.WriteLine(item.ToString());
- }
- }
- Console.ReadKey();
- }
- //声明GetArrayList方法,该方法返回ArrayList实例
- static ArrayList GetArrayList()
- {
- ArrayList al = new ArrayList();
- //添加元素
- al.Add(10);
- al.Add(15);
- al.Add(13.98);
- al.Add("Hell word");
- al.Add(DateTime.Today);
- return al;
- }
- }
- }
复制代码 |