我一直在尝试使用 C# 和 Windows 表单编写一个基本的漫画书管理应用程序。但是我一直收到错误
CS7036- 没有给出与所需形式参数对应的参数。
任何人都可以建议我如何克服这个问题,因为它已经让我难倒了一段时间了?
添加漫画表单代码
public partial class AddComic : Form
{
public AddComic()
{
InitializeComponent();
}
static void main()
{
ComicClass comic1 = new ComicClass();
comic1.SetTitle("IronMan");
}
private void button1_Click(object sender, EventArgs e)
{
//Create New Comic Book
ComicClass newComic;
newComic = new ComicClass();
if (txtTitle.Text != "")
{
newComic.SetTitle(txtTitle.Text);
}
if (txtPublisher.Text != "")
{
newComic.SetPublisher(txtPublisher.Text);
}
if (txtAuthor.Text != "")
{
newComic.SetAuthor(txtAuthor.Text);
}
if (txtIllustrator.Text != "")
{
newComic.SetIllustrator(txtIllustrator.Text);
}
if (txtIssueNumber.Text != "")
{
newComic.SetIssueNumber(txtIssueNumber.Text);
}
if (txtReleaseDate.Text != "")
{
newComic.SetReleaseDate(txtReleaseDate.Text);
}
try
{
if (txtCost.Text != "")
{
newComic.SetCost(Convert.ToDouble(txtCost.Text));
}
}
catch
{
MessageBox.Show("The Cost Must be formated 00.00");
return;
}
}
}
漫画课
class ComicClass
{
private String sTitle;
private String sPublisher;
private String sAuthor;
private String sIllustrator;
private String sIssueNumber;
private String sReleaseDate;
private double dCost;
//Accessor & Mutator for the Title//
public String GetTitle()
{
return sTitle;
}
public void SetTitle(String psTitle)
{
sTitle = psTitle;
}
//Accessor & Mutator for the Publisher//
public String GetPublisher()
{
return sPublisher;
}
public void SetPublisher(String psPublisher)
{
sPublisher = psPublisher;
}
//Accessor & Mutator for the Author//
public String GetAuthor()
{
return sAuthor;
}
public void SetAuthor(String psAuthor)
{
sAuthor = psAuthor;
}
//Accessor & Mutator for the Illustrator//
public String GetIllustrator()
{
return sIllustrator;
}
public void SetIllustrator(String psIllustrator)
{
sIllustrator = psIllustrator;
}
//Accessor & Mutator for the Issue Number//
public String GetIssueNumber()
{
return sIssueNumber;
}
public void SetIssueNumber(String psIssueNumber)
{
sIssueNumber = psIssueNumber;
}
//Accessor & Mutator for the Release Date//
public String GetReleaseDate()
{
return sReleaseDate;
}
public void SetReleaseDate(String psReleaseDate)
{
sReleaseDate = psReleaseDate;
}
//Accessor & Mutator for the Cost//
public double GetCost()
{
return dCost;
}
public void SetCost(double pdCost)
{
dCost = pdCost;
}
//Constructor//
public ComicClass (String psTitle,String psAuthor, String psIllustrator, String psIssueNumber, String psRelaseDate, double pdCost)
{
sTitle = psTitle;
sAuthor = psAuthor;
sIllustrator = psIllustrator;
sIssueNumber = psIssueNumber;
sReleaseDate = psRelaseDate;
dCost = pdCost;
}
static void main(string [] args)
{
}
这里
public ComicClass (String psTitle,String psAuthor, String psIllustrator, String psIssueNumber, String psRelaseDate, double pdCost)
你说构造函数需要一大堆参数。这里
ComicClass comic1 = new ComicClass();
您可以在没有这些参数的情况下调用它
你需要
ComicClass comic1 = new ComicClass("x","y","z",...);
顺便说一句,称类XXXClass是经典的反模式,就叫它漫画吧
并使用 c# 属性,而不是你自己的 Get 和 Set 方法
你的漫画课应该是这样的
public class Comic
{
public string Title {get;set;}
public string Author {get;set;}
...
}
现在你可以做
var comic = new Comic
{
Title = "xxxx",
Author = "yy"
};
...
comic.Title = "Changed my mind"