当尝试从相同的类名为类创建构造函数时。 为什么会报错如下:
“错误:'StaveProcessor':成员名称不能与其封闭类型相同”
代码:
namespace ImageProcessing
{
class StaveProcessor
{
public Bitmap stave;
public StaveProcessor(Bitmap image) //constructor
{
stave = image;
}
}
}
如何解决这个问题并创建构造函数?
ps:请自认为不是专家,请原谅我提出愚蠢的问题,帮助我学习和识别。谢谢
最佳答案
好吧,您提供的代码没有任何问题(它可以编译),如果您执行以下操作,将会显示您得到的异常:
class StaveProcessor
{
// can't have this method with this name (note the void, it's not a constructor)
public void StaveProcessor(Bitmap image)
{
stave = image;
}
}
关于c# - 创建构造函数时报错 "member names cannot be the same as their enclosing type"是什么意思,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17509603/