也许我误解了构造函数的工作原理,但无论如何,我试图创建一个数组并将其填充到构造函数中。
我有以下代码 -
class ClsDeck
{
private string[] deck = new string[52];
private string[] hand = new string[12];
BuildDeck()
{
//lots of code assigning images to each individual element of the "deck" array.
}
//many other methods that need to be called by a form.
}
Visual Studio 2012 坚持该方法具有返回类型。我只是在 BuildDeck 方法中添加了“void”,错误就消失了,但是我看到的每个构造函数示例都必须与类同名,并且它是类中唯一的方法。