获取“成员名称不能与其封闭类型相同”[关闭](Getting “Member names cannot be the same as their enclosing type” [closed])

编程入门 行业动态 更新时间:2024-10-28 09:18:28
获取“成员名称不能与其封闭类型相同”[关闭](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) { }

更多推荐

本文发布于:2023-07-23 22:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   名称   类型   Member   closed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!