CS7036 Visual Studo No Formal Parameters

时间:2017-08-17 15:34:03

标签: c# winforms visual-studio visual-studio-2015

我一直在尝试使用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;
        }




    }
  }

ComicClass

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




    }

1 个答案:

答案 0 :(得分:1)

这里

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",...);
BTW,调用类XXXClass是一个经典的反模式,只需称之为Comic

并使用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"