我正在尝试自学 C#,但在使用此代码时遇到了问题:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
contacts.Add(new Contact()
{
Name = "James",
Email = "james@mail.com",
PhoneNumber = "01234 111111"
});
contacts.Add(new Contact()
{
Name = "Bob",
Email = "bob@mail.com",
PhoneNumber = "01234 222222"
});
contacts.Add(new Contact()
{
Name = "Emma",
Email = "emma@mail.com",
PhoneNumber = "01234 333333"
});
}
protected List<Contact> contacts = new List<Contact>();
public List<Contact> Contacts
{
get { return contacts; }
set { contacts = value; }
}
private void NewContactButton_Click(object sender, RoutedEventArgs e)
{
contacts.Add(new Contact()
{
Name = NameTextBox.Text,
Email = EmailTextBox.Text,
PhoneNumber = PhoneTextBox.Text
});
}
}
}
它没有在列表中显示新联系人,我不确定它是否正在创建新联系人。它显示前三个非常好。
我有一种感觉,我遗漏了一些重要的东西。