zoukankan      html  css  js  c++  java
  • 泛型方法扩展

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    using System.Reflection;
    using System.Text.RegularExpressions;

    namespace ConsoleApplication1
    {
        public static class Program
        {
            /// <summary>
            
    /// 入口函数
            
    /// </summary>
            
    /// <param name="args"></param>
            static void Main(string[] args)
            {
                List<string> oldStrList = new List<string>()
                {
                    "12","ZH","CN","2E","0A","56","FF","00"
                };

                Console.Write("Old List:" + oldStrList.Count + " ->");
                foreach (string str in oldStrList) Console.Write(str + " ");

                Console.WriteLine(""); 

                List<string> newHexList = oldStrList.HexFilter(
                    (p) => 
                        {
                            bool blStatus = false;

                            try
                            {
                                Convert.ToInt32(p, 16); blStatus = true;
                            }
                            catch
                            {
                                blStatus = false;
                            }

                            return blStatus; 
                        }
                    ).ToList();

                Console.Write("New List:" + newHexList.Count + " ->");
                foreach (string str in newHexList) Console.Write(str + " ");

                Console.ReadLine();
            }
            /// <summary>
            
    /// 过滤掉非十六进制字符
            
    /// </summary>
            
    /// <typeparam name="T"></typeparam>
            
    /// <param name="source"></param>
            
    /// <param name="predicate"></param>
            
    /// <returns></returns>
            static IEnumerable<T> HexFilter<T>(this IEnumerable<T> source, Func<T, bool> predicate)
            {
                foreach (T item in source)
                {
                    if (predicate(item)) yield return item;
                }
            }
        }
    }
  • 相关阅读:
    Java线程安全和非线程安全
    时间戳获取(周,年,月,日)
    spring+spring 日志输出
    Spring+springMvc+Mybatis
    关于mysql处理百万级以上的数据时如何提高其查询速度的方法
    Tomcat 详解
    理解 $_POST、$_GET 、php://input
    php编译参数注解--不明白许多参数的作用 慎用 –with-curlwrappers参数【转载】
    centos6.5编译安装php[整理一]
    ubuntu16.04 安装chrome 和 phpstorm
  • 原文地址:https://www.cnblogs.com/zhangpengshou/p/2773571.html
Copyright © 2011-2022 走看看