【发布时间】:2021-12-08 15:39:11
【问题描述】:
我在统一控制台中收到此错误,但我找不到问题所在。我认为一切都是正确的?我只是从 udemy 的 curs 中写下来,他使用 Visual Studio,而我使用 vsc,我认为这不是问题。但它显然是相同的,它在教程中的外观。感谢帮助。
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;
}
}
统一错误 -> 错误 CS7036:没有给出与“Student.Student(string, string, string, int)”所需的形参“age”相对应的参数
【问题讨论】:
-
您在 `Student("Jordan", "Smith", 31);` 中缺少一个参数;` 构造函数有 4 个参数而不是 3 个
-
不清楚为什么您希望调用者在计算时传递
fullName,所以也许您打算删除该参数?