我以前学习过Python,因此刚开始学习C#。我知道类和构造函数如何在Python中使用init(self,...)
我正在学习有关C#的Giraffe Academy / FreeCodeCamp教程,并且我和他所做的事情完全相同(无论如何我都看不出任何区别)。但是,在尝试为书类创建构造函数时仍然出现错误。这是我的代码,我从中得到5个不同的错误:
namespace StuffThingy
{
class Book
{
public string title;
public string author;
public int pages;
}
public Book(string aTitle,string aAuthor, int aPages)
{
title = aTitle;
author = aAuthor;
pages = aPages;
}
就像它无法识别我在构造函数中使用公共变量之前就定义了公共变量
尝试将构造方法放在类中。