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
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