且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不包含一个构造函数4个参数?

更新时间:2022-12-08 19:41:07

声明一个构造函数4个参数:

 类用户
{
    公众用户(串名字,字符串姓氏,字符串的地址,串电话)
    {
       _fName =名字;
       ....
    }
}
 

用法:

 用户的用户=新用户(乔,...);
 


或增加公共二传手类的属性,然后使用对象初始化:

 公共字符串名字{获得;组; } //通知公众
 

用法:

 用户的用户=新用户{名字=乔,...};
 

I'm fairly new to programming and I've been stuck on this question for awhile now, I have searched for an answer to this question throughout the internet but am still stumped as to why it is not working. The compiler says that the code below does not contain a constructor that takes 4 arguments? I don't understand why?

The code is:

public class Users
{
    private int _ID;
    private string _FName;
    private string _LName;
    private string _Address;
    private string _Phone;

    public int ID
    {
        get { return _ID; }
    }

    public string FName
    {
        get { return _FName; }
    }

    public string LName
    {
        get { return _LName; }
    }

    public string Address
    {
        get { return _Address; }
    }

    public string Phone
    {
        get { return _Phone; }
    }
}

The code that is having trouble is:

public static void Insert(string FName, string LName, string Address, string Phone)
{
    Users newUser = new Users(FName, LName, Address, Phone);
    newUser.Save();
}

Declare a constructor that takes 4 arguments:

class User
{
    public User(string firstName, string lastName, string address, string phone)
    {
       _fName = firstName;
       ....
    }
}

Usage:

User user = new User("Joe", ...);


or add public setter to class properties, then use object initializer:

public string FirstName { get; set; } // notice public

Usage:

User user = new User { FirstName = "Joe", ... };