Use object between multiple functions

后端 未结 2 1425
我在风中等你
我在风中等你 2021-01-26 22:57

I am creating a spam email checker. One method scans the email, another adds a known flag to an array of words and phrases to check against; both methods are part of Teste

2条回答
  •  一向
    一向 (楼主)
    2021-01-26 23:19

    Move the Tester variable to the class field, like this:

    public partial class Spam_Scanner : Form
    {
        Tester scan;
    
        public Spam_Scanner()
        {
            InitializeComponent();
            scan = new Tester();
        }
    
        private void testButton_Click(object sender, EventArgs e)
        {            
            scan.tester(Convert.ToString(emailBox.Text));
            this.SpamRatingBox.Text = string.Format("{0:N1}%", Tester.countSpam / Tester.wordCount * 100);
            this.WordsBox.Text = Tester.posSpam;
            this.OutputPanal.Visible = true;
            this.pictureBox1.Visible = false;
        }
    
        private void addButton_Click(object sender, EventArgs e)
        {
            scan.addSpam(Convert.ToString(addFlagBox.Text));
            this.addFlagBox.Text = "";
        }
    }
    

提交回复
热议问题