获取 "Member names cannot be the same as their enclosing type"
Getting "Member names cannot be the same as their enclosing type"
我从 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;
}
}
但是当我写构造函数时,我收到了错误:
Member Names cannot be the same as their enclosing type
我在这里看到其他一些人遇到了这个问题,但答案并不能解决我的问题。
也许这里有人提示我解决这个问题?
从构造函数签名中删除 "void":
public ShapeItems(...) { }
您没有构造函数,只有方法:void
。删除 void
这个词,它应该可以工作。
所以
public ShapeItems(params) { }
而不是
public void ShapeItems(params) { }
我从 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;
}
}
但是当我写构造函数时,我收到了错误:
Member Names cannot be the same as their enclosing type
我在这里看到其他一些人遇到了这个问题,但答案并不能解决我的问题。
也许这里有人提示我解决这个问题?
从构造函数签名中删除 "void":
public ShapeItems(...) { }
您没有构造函数,只有方法:void
。删除 void
这个词,它应该可以工作。
所以
public ShapeItems(params) { }
而不是
public void ShapeItems(params) { }