获取“成员名称不能与其封闭类型相同”[关闭](Getting “Member names cannot be the same as their enclosing type” [closed])
我从Java了解构造函数,现在有一个C#项目。 两种语言的语法非常相似,所以我认为这应该不是问题:
class ShapeItems { public String masterName = ""; public String stencilName = ""; public Double coordY = 0.0; public Double coordX = 0.0; public String shapeText = ""; public void ShapeItems(String mN, String sN, Double X, Double Y, String sT) { this.masterName = mN; this.stencilName = sN; this.coordX = X; this.coordY = Y; this.shapeText = sT; } }但是当我编写构造函数时,我收到了错误:
成员名称不能与其封闭类型相同
我在这里见过其他一些有这些问题的人,但答案不会解决我的问题。
也许这里有人提示我解决这个问题?
I knew constructors from Java and have now a C# project. Syntax in both languages is very similar, so I thought this shouldn't be a problem:
class ShapeItems { public String masterName = ""; public String stencilName = ""; public Double coordY = 0.0; public Double coordX = 0.0; public String shapeText = ""; public void ShapeItems(String mN, String sN, Double X, Double Y, String sT) { this.masterName = mN; this.stencilName = sN; this.coordX = X; this.coordY = Y; this.shapeText = sT; } }But as I wrote the constructor, I received the error:
Member Names cannot be the same as their enclosing type
I've seen some others with this problems here, but the answers won't fix my problem.
Maybe someone here has a hint for me to solve this issue?
最满意答案
你没有构造函数,只有一个方法: void 。 删除单词void ,它应该工作。
所以
public ShapeItems(params) { }代替
public void ShapeItems(params) { }You don't have a constructor but a method: void. Remove the word void and it should work.
So
public ShapeItems(params) { }instead of
public void ShapeItems(params) { }更多推荐
发布评论