【问题标题】:c# There is no argument given that corresponds to the required formal parameter errorc#没有给定的参数对应于所需的形参错误
【发布时间】:2020-05-22 16:22:55
【问题描述】:

我收到一条错误消息:

错误 CS7036 没有给出与 'Person.Person(string, int, string) 的所需形式参数 'email' 对应的参数,

我是新手,所以不确定,但感谢帮助,谢谢

编辑:它是在我的程序中以红色突出显示的“基础”

public class Student : Person
{
    /// <summary>
    /// student ID number
    /// </summary>
    private String Postcode;    // student ID number

    public Student() : base("(unknown name)", 0000)
    {
        Postcode = "(unknown ID)";
    }

    /// <summary>
    /// Create a student with given name, year of birth and student ID
    /// </summary>
    /// <param name="name">name</param>
    /// <param name="dateOfBirth">year of birth</param>
    /// <param name="Postcode2">ID</param>

    public Student(String name, int dateOfBirth, String Postcode2, string email) : base(name, dateOfBirth, email)
    {
        Postcode = Postcode2;
    }

    /// <summary>
    /// read only poperty for ID
    /// </summary>
    public string PostalCode
    {
        get { return Postcode; }
    }


    /// <summary>
    /// Return a string representation of this object.
    /// </summary>
    /// <returns>string representation of Student object</returns>
    public override String ToString()    // redefined from "Person"
    {
        return base.ToString() +
               "Student Member\n" +
               "Postcode: " + Postcode + "\n";
    }
}

【问题讨论】:

  • 我们需要查看您的Person 课程。
  • dateOfBirthint 表示而不是DateTime 似乎很奇怪。

标签: c# visual-studio


【解决方案1】:

basePerson 正在实现的Person 类,错误意味着您没有将必需的参数传递给它的构造函数(名为email):

base("(unknown name)", 0000) // This only passes 2 parameters to the Person constructor

要解决此问题,您需要向Person 类添加一个不需要 需要email 的构造函数,或者传递一个默认值(就像您为@987654328 所做的那样@:

public Student() : base("(unknown name)", 0, "(unknown email)")
{
    Postcode = "(unknown ID)";
}

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 2023-02-15
    • 2017-07-18
    • 2021-04-20
    • 2017-09-30
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    相关资源
    最近更新 更多