c#将新命名空间添加到项目中

tee*_*tee 2 c#

如何在ac #project中添加命名空间?我是初学者.

if(!string.IsNullOrEmpty(result))
{
    CoderBuddy.ExtractEmails helper = new CoderBuddy.ExtractEmails(result);
    EmailsList = helper.Extract_Emails;
}
Run Code Online (Sandbox Code Playgroud)

我的Form1需要使用以下命名空间:

// this is the file that I need to add
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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

tzu*_*zup 5

好吧,在你的.cs页面中添加一个using语句

using Coderbuddy;
Run Code Online (Sandbox Code Playgroud)

然后您的代码可以访问此类型公开的方法.

或者,将您的winform .cs文件放在同一名称空间中(不是推荐的想法)