查找集合中某个元素的位置和某个元素的集合

        List<string> list = new List<string>();
        list.AddRange(new string[] { "gh", "gfh", "张三", "李四", "李1", "李2" });
        Predicate<string> pre = new Predicate<string>(IsString);
        int a =  list.FindIndex(pre);

        Predicate<string> pre1 = new Predicate<string>(GetString);
        List<string> list1 = list.FindAll(pre1);

 

 

 

 

    /// <summary>
    /// 筛选条件1
    /// </summary>
    /// <param name="abc"></param>
    /// <returns></returns>
    private bool IsString(string param)
    {
        if (param == "李四")
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /// <summary>
    /// 筛选条件2
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    private bool GetString(string param)
    {
        if (param.StartsWith("李"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

你可能感兴趣的:(集合)