目前得到一個錯誤,下面的代碼,我不知道如何解決它!將對象添加到列表,不能分配給添加,因爲它是一個組方法
這是錯誤:
這是我App.xaml.cs:
public partial class App : Application
{
//Public list of users and form can access
List<User> LoggedUsers = new List<User>();
//First startup of the application
public void Application_Startup(object sender, StartupEventArgs e)
{
//First startup, display the login form
LoginWindow FirstLogin = new LoginWindow();
FirstLogin.ShowDialog();
//If the login form was closed properly, handle the user
if (FirstLogin.DialogResult == true)
{
//Add the user to the list of logged users
User returned = FirstLogin.returnUser;
//Create temp duplicate for testing
User tmp = new User();
tmp.Email = "[email protected]";
tmp.FirstName = "John";
tmp.LastName = "Johnson";
tmp.ID = "01";
tmp.Permissions = 1;
LoggedUsers.Add = tmp;
LoggedUsers.Add = returned;
}
}
}
這裏是我的LoginWindow.xaml.cs該用戶對象是從何時關閉返回(返回):
//Give App access to user object outside of this form
public User returnUser
{
get
{
return user;
}
}
//Public user object, start empty
User user = new User();
//Check the login
private void doLogin(string username, string password)
{
//User logged in, add data to user object
user.Email = "[email protected]";
user.FirstName = "John";
user.LastName = "Johnson";
user.ID = "01";
user.Permissions = 1;
//Close the form with dialog result "true"
this.DialogResult = true;
this.Close();
}
和類,櫃面你需要:
//Logged in users class
Public Class User
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public Int16 Permissions { get; set; }
}
當我解決了這個問題時,爲了某些測試目的將一個重複的對象添加到列表中。
Woops對不起,忘了,因爲它是讓我當場打死數等待幾分鐘。 – 2014-10-01 15:29:16