“字符串'不包含定义'包含' [英] 'string' does not contain a definition for 'Contains'

查看:278
本文介绍了“字符串'不包含定义'包含'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像这样的声明:

var vals =
    from StandAloneUserPayment saup in _Session.Query<StandAloneUserPayment>()
        .Fetch(x => x.RecurringPayments)
    where
        saup.User.UserId == userId
        && searchString.Contains(saup.FriendlyName, StringComparer.InvariantCultureIgnoreCase)
    select
        saup;

这似乎正是我应该做的,但我得到了整个符合包含方法,以下信息强调:

This seems to be exactly what I'm supposed to do, but I get the whole line with the Contains method underlined with the following message:

字符串不包含的定义包含和最佳推广方法重载 System.Linq.ParallelEnumerable.Contains< TSource>( System.Linq.ParallelQuery< TSource>中TSource,System.Collections.Generic.IEqualityComparer< TSource>)有一些无效参数

string does not contain a definition for Contains and the best extension method overload System.Linq.ParallelEnumerable.Contains<TSource>(System.Linq.ParallelQuery<TSource>, TSource, System.Collections.Generic.IEqualityComparer<TSource>) has some invalid arguments

我在做什么错了?

推荐答案

尝试的IndexOf

searchString.IndexOf(saup.FriendlyName,
                     StringComparison.InvariantCultureIgnoreCase) != -1

它不工作的原因是因为包含接受扩展方法的的IEqualityComparer< TSource> 是在字符串,它实现了的IEnumerable和下操作;焦炭> ,而不是的IEnumerable<串> ,所以字符串的IEqualityComparer<字符串方式> 不能被传递给它

The reason it doesn't work is because the Contains extension method that accepts an IEqualityComparer<TSource> is operating on a String, which implements IEnumerable<char>, not IEnumerable<string>, so a string and an IEqualityComparer<string> can't be passed to it.

这篇关于“字符串'不包含定义'包含'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆