Error The call is ambiguous between the following methods or properties

Viewed 2773
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);
            }
        }

    }
}

Generating error

The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Cast(System.Collections.IEnumerable)' and 'System.Linq.Enumerable.Cast(System.Collections.IEnumerable)'

Throwing this error at matches.Cast() line number 27 and similar instances. any help would be appericiated.

0 Answers
Related