将对象添加到列表,无法分配给Add,因为它是一个组方法

Mar*_*all 0 c# wpf

目前使用以下代码收到错误,我不知道如何修复它!

这是错误: 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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的LoginWindow.xaml.cs,它在关闭(返回)时返回User Object:

//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();
}
Run Code Online (Sandbox Code Playgroud)

这个课程,你需要这个:

//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; }
}
Run Code Online (Sandbox Code Playgroud)

我已修复此问题时,为了某些测试目的,将重复的对象添加到List中.

Mit*_*eat 7

List.Add() 是一种方法而不是财产:

LoggedUsers.Add(tmp);
LoggedUsers.Add(returned);
Run Code Online (Sandbox Code Playgroud)