小编T17*_*772的帖子

为什么我的C#构造函数不能使用我正在尝试使用的方法?

也许我误解了构造函数是如何工作的,但无论如何,我正在尝试创建一个数组并在构造函数中填充它.

我有以下代码 -

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",并且错误消失了,但是我看到的构造函数的每个例子都必须与类具有相同的名称,并且它是类中唯一的方法.

c# class-constructors

3
推荐指数
1
解决办法
494
查看次数

标签 统计

c# ×1

class-constructors ×1