扩展方法

扩展方法三要素: 静态类、静态方法、 this关键字。
扩展方法被定义为静态方法,但它们是通过实例方法语法进行调用的。 它们的第一个参数指定该方法作用于哪个类型,并且该参数以 this 修饰符为前缀。 扩展方法当然不能破坏面向对象封装的概念,所以只能是访问所扩展类的public成员。
Contains
public static bool Contains(this string source, string str, bool isIgnoreLower)
    {
        if(isIgnoreLower)
        {
            return source.ToLower().Contains(str.ToLower());
        }

        return source.Contains(str);
    }
原文地址:https://www.cnblogs.com/xiaonangua/p/9173138.html