Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't solve error CS7036 in unity: There is no argument given that corresponds to the required formal parameter

I got this error in the unity console, but I can’t find the problem. I think everthing is correct? I just write it down from a curs in udemy, he uses visual studio, and i use vsc, i dont think that is a problem. but its clearly the same, how it looks in the tutorial.thanks for help.

1/2 properties.cs:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Properties : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        /* EIGENSCHAFTEN (C# Properties) */

        Student Jordan = new Student("Jordan", "Smith", 31);

        Debug.Log(Jordan.FirstName);
        Debug.Log(Jordan.LastName);
        Debug.Log(Jordan.FullName);
        Debug.Log(Jordan.Age);




    }
}

2/2 student.cs

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Student
{

    public string FirstName { get; set; }
    public string LastName { get; set; }

    public string FullName { get { return this.FirstName + " " + this.LastName; } }

    public int Age { get; private set; }

    public Student(string firstName, string lastName, string fullName, int age)
    {
        FirstName = firstName;
        LastName = lastName;
        Age = age;
    }

}

error in unity -> error CS7036: There is no argument given that corresponds to the required formal parameter ‘age’ of ‘Student.Student(string, string, string, int)’

>Solution :

You have only passed 3 parameters to your constructor but you defined it with 4

Since you have custom getter for FullName i guess best solution for you would be to remove it from constructo

public Student(string firstName, string lastName, int age)
{
    FirstName = firstName;
    LastName = lastName;
    Age = age;
}

Alternative would be just to overload contstructor and write another combination for it

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading