我刚开始学习C#,刚开始学习面向对象编程。我正在使用visualstudio,我得到错误代码CS7036:没有与Book.Book所需的形式参数"keywords"相对应的参数。正在尝试使其输出图书信息。
下面是我的主要代码。。。
using System;
namespace BookProgram
{
class Program
{
static void Main(string[] args)
{
Book newBook = new Book("Orson Scott Card, Enders Game, Science Fiction, January 15th 1985", 0812550706);
Console.WriteLine(newBook.ToString());
}
}
}
这是分类代码
using System;
using System.Collections.Generic;
using System.Text;
namespace BookProgram
{
public class Book
{
private string _author;
private string _title;
private string _keywords;
private string _publicationDate;
private int _isbn;
public Book()
{
_author = "";
_title = "";
_keywords = "";
_publicationDate = "";
_isbn = 0;
}
public Book(string author, string title, string keywords, string publicationDate, int isbn)
{
_author = author;
_title = title;
_keywords = keywords;
_publicationDate = publicationDate;
_isbn = isbn;
}
public string Author { get => _author; set => _author = value; }
public string Title { get => _title; set => _title = value; }
public string Keywords { get => _keywords; set => _keywords = value; }
public string PublicationDate { get => _publicationDate; set => _publicationDate = value; }
public int ISBN { get => _isbn; set => _isbn = value; }
public override string ToString()
{
return ("AUTHOR: " + Author + " TITLE: " + Title + " KEYWORDS: " + Keywords + " PUBLICATION DATE: "
+ PublicationDate + " ISBN: " + ISBN);
}
}
}
替换
Book newBook = new Book("Orson Scott Card, Enders Game, Science Fiction, January 15th 1985", 0812550706);
带有
Book newBook = new Book("Orson Scott Card", "Enders Game", "Science Fiction", "January 15th 1985", 0812550706);
否则,它只是作为一个字符串+一个整数而不是5个必需的参数传递
您应该考虑将DateTime
类型用于publicationDate
,将string
类型用于isbn