将对象添加到列表,不能指定给Add,因为它是一种分组方法
本文关键字:一种 方法 Add 列表 添加 对象 不能 因为 | 更新日期: 2023-09-27 18:25:13
当前以下代码出现错误,我不知道如何修复!
这是错误:Cannot assign to 'Add' because it is a 'method group'
这是我的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@gmail.com";
tmp.FirstName = "John";
tmp.LastName = "Johnson";
tmp.ID = "01";
tmp.Permissions = 1;
LoggedUsers.Add = tmp;
LoggedUsers.Add = returned;
}
}
}
这是我的LoginDow.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@gmail.com";
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; }
}
当我修复了这个问题时,为了一些测试目的,将一个重复的对象添加到列表中。
List.Add()
是一个方法而不是属性:
LoggedUsers.Add(tmp);
LoggedUsers.Add(returned);