【发布时间】:2014-03-07 05:47:07
【问题描述】:
所以我得到了这个错误,我不太明白为什么我得到它。我曾尝试在这里寻找答案,但每个问题都非常独特,因此不适用于我的问题。
这是我目前所拥有的。
class customer{
public string sFirstName { get; set; }
public string sLastName { get; set; }
public int iAge { get; set; }
}
class customerObject{
public static List<customer> lstStaticUsers { get; set; }
public customerObject(){
lstStaticcustomer = new List<customer>();
}
public static void AddNewStaticUser(string FirstName, string LastName, int Age)
{
lstStaticcustomer.Add(new customer{sFirstName = FirstName, sLastName = LastName, iAge = Age});
}
}
这是我的窗口
public partial class wndCustomerInfo : Window
{
public wndCustomerInfo ()
{
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Hide();
e.Cancel = true;
}
private void btnSubmitForm_Click(object sender, RoutedEventArgs e)
{
customerObject.AddNewStaticcustomer(txtFirstName.Text, txtLastName.Text, Convert.ToInt32(txtAge.Text));
lblMessage.Content = "Created new user: " + txtFirstName.Text;
}
}
然后这是我打开上面那个的主窗口
public partial class MainWindow : Window
{
wndCustomerInfo wndCustomerInfoForm;
public MainWindow()
{
InitializeComponent();
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
wndCustomerInfoForm= new wndCustomerInfo ();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
this.Hide();
wndCustomerInfoForm.ShowDialog();
this.Show();
}
}
如果有人可以提供帮助,那就太好了。我是 C# 的新手,所以请善待
【问题讨论】: