C# 字符串匹配时出错?

C# 字符串匹配时出错?,c#,C#,我正试图捕捉下面的异常消息,并遇到下面的错误,有人能提供关于如何解决这个问题的输入吗?有没有更好的方法来处理字符串匹配 catch (Exception ex) { ////catch { if (ex.Message.Contains("Reading from the stream has failed", StringComparison.

我正试图捕捉下面的异常消息,并遇到下面的错误,有人能提供关于如何解决这个问题的输入吗?有没有更好的方法来处理字符串匹配

            catch (Exception ex)
            {
                ////catch
                {
                    if (ex.Message.Contains("Reading from the stream has failed", StringComparison.OrdinalIgnoreCase))
                    {
                        throw;
                    }

                    else
                    {
                        throw;
                    }

                }
      }
错误1实例参数:无法从“字符串”转换为“System.Linq.IQueryable”

错误2“字符串”不包含“Contains”的定义,最佳扩展方法重载“System.Linq.Queryable.containsssystem.Linq.IQueryable,TSource,System.Collections.Generic.IEqualityComparer”具有一些无效参数

错误3参数3:无法从“System.StringComparison”转换为“System.Collections.Generic.IEqualityComparer”C:\Users\gnakkala\gnakkala_dashboard\source\qcom\qca\wconnect\wbit\automation\dashboard\sandbox\dashboard.Data.Repository\BuildRepositories\LookaheadGerritsRepository.cs”


没有字符串。包含接受StringComparison的方法。大多数人最终使用IndexOf调用来实现此目的。

您应该了解有关结构化异常处理的更多信息。当您有其他更健壮的方法可用时,尝试分析错误消息并不是正确的方法。@weston:事实上,消息.Contains。。。call是导致问题的代码。@SamAxe-您所指的健壮方法是什么?Warrior-请建议字符串使用什么方法comparison@JeffShort当前位置你看了我把这个问题的答案标记为的副本了吗?我看到了,我正在使用相同的。。contains@JeffShort:将使用。从流中读取IndexOfReading失败,StringComparison.OrdinalIgnoreCase>=0