Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

c# Cannot convert method group

how can  I fix this problem

Error      1      Cannot convert method group 'Extract_Emails' to non-delegate type 'string[]'. Did you intend to invoke the method?      C:\Users\¿¿¿7\documents\visual studio 2010\Projects\emailsearch\emailsearch\Form1.cs      37      34      emailsearch


if(!string.IsNullOrEmpty(result))
                {
                    Coderbuddy.ExtractEmails helper = new Coderbuddy.ExtractEmails(result);
                    EmailsList = helper.Extract_Emails;

                }
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Coderbuddy
{
    public class ExtractEmails
    {
        private string s;
        public ExtractEmails(string Text2Scrape)
        {
            this.s = Text2Scrape;
        }
        public string[] Extract_Emails()
        {
            string[] Email_List = new string[0];
            Regex r = new Regex(@"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}", RegexOptions.IgnoreCase);
            Match m;
            //Searching for the text that matches the above regular expression(which only matches email addresses)
            for (m = r.Match(s); m.Success; m = m.NextMatch())
            {
                //This section here demonstartes Dynamic arrays
                if (m.Value.Length > 0)
                {
                    //Resize the array Email_List by incrementing it by 1, to save the next result
                    Array.Resize(ref Email_List, Email_List.Length + 1);
                    Email_List[Email_List.Length - 1] = m.Value;
                }
            }
            return Email_List;
        }
    }
}

Open in new window

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

You are returing a list of strings, and you try to put it in a single string.

Try this:

if(!string.IsNullOrEmpty(result))
                {
                    Coderbuddy.ExtractEmails helper = new Coderbuddy.ExtractEmails(result);
                    string[] EmailsList = helper.Extract_Emails;

                }
Avatar of MrTV

ASKER

Hi Dhaest
delemailed.png
Avatar of MrTV

ASKER

i try
EmailsList = helper.Extract_Emails();
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did it solve your problem ?
Avatar of MrTV

ASKER

Thank you