错误以下方法或属性之间的调用不明确

时间:2017-09-22 09:25:23

标签: c# winforms linq

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace DiffCalc
{
    public partial class newResult : Form
    {
        public newResult()
        {
            InitializeComponent();
        }

        private void newResult_Load(object sender, EventArgs e)
        {
            string s1 = "Have a very good";
            string s2 = "Have a very good day, Joe";
            IEnumerable<string> diff;
            MatchCollection matches = Regex.Matches(s1, @"\b[\w']*\b");

            IEnumerable<string> first = from m in matches.Cast<Match>()
                                       where !string.IsNullOrEmpty(m.Value)
                                       select TrimSuffix(m.Value);
            MatchCollection matches1 = Regex.Matches(s2, @"\b[\w']*\b");
            IEnumerable<string> second = from m in matches1.Cast<Match>()
                                         where !string.IsNullOrEmpty(m.Value)
                                         select TrimSuffix(m.Value);

            if (second.Count() > first.Count())
            {
                diff = second.Except(first).ToList();
            }
            else
            {
                diff = first.Except(second).ToList();
            }
        }
        static string TrimSuffix(string word)
        {
            int apostropheLocation = word.IndexOf('\'');
            if (apostropheLocation != -1)
            {
                word = word.Substring(0, apostropheLocation);
            }
        }

    }
}

生成错误

  

以下方法或属性之间的调用不明确:'System.Linq.Enumerable.Cast(System.Collections.IEnumerable)'和'System.Linq.Enumerable.Cast(System.Collections.IEnumerable)'

抛出此错误 matches.Cast() 第27行和类似的实例。任何帮助都会被暗示。

0 个答案:

没有答案
相关问题