0

我目前正在使用以下代码:

private void NewContactSaveButton_Click_1(object sender, EventArgs e)
{
    if (NewContactTextBoxName.Text == "")
    {
        MessageBox.Show("Please enter a Contact Name");
    }
    else
    {   
        ContactInformation.ContactName = NewContactTextBoxName.Text;
        string contactpath2 = @"CurrentContacts.txt";
        string contactpath3 = @"" + ContactInformation.ContactName + ".txt";
        string Readfile = File.ReadAllText(contactpath2);
        if (Readfile.Contains(ContactInformation.ContactName))
        {
            MessageBox.Show("This contact already exsists. Please rename the contact you're trying to create or delete the exsisting contact");
        }
        else
        {
            //save contact to file
        }
    }
}

以及以下类文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contact_List
{
    public class ContactInformation
    {
        public static string ContactName;
        public static string ContactCellNumber;
        public static string ContactOtherNumber;
        public static string ContactRelationship;
        public static string ContactEmail;
        public static string ContactNote;
    }
}

我的问题是以下代码行:

MessageBox.Show("This contact already exists. Please rename the contact you're trying to create or delete the existing contact");

单击保存按钮时始终运行。我不明白为什么并且希望它只在它是真的时运行。

4

0 回答 0