目前得到一个错误,下面的代码,我不知道如何解决它!将对象添加到列表,不能分配给添加,因为它是一个组方法
这是错误:
这是我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