也许我误解了构造函数是如何工作的,但无论如何,我正在尝试创建一个数组并在构造函数中填充它.
我有以下代码 -
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.
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2012坚持该方法具有返回类型.我只是在BuildDeck方法中添加了"void",并且错误消失了,但是我看到的构造函数的每个例子都必须与类具有相同的名称,并且它是类中唯一的方法.