Cause for CS0542 - "member names cannot be the same as their enclosing type"
.net, c#
Solution
The problem is here:
public void SuperTeam(string nSuperTeamName)
{
SuperTeamName = nSuperTeamName;
}
I believe you wanted to have a constructor for your class, and since constructor can't have a return type, the compiler is treating it as a method. Now the method name is same as the class name, that is why you are getting the error.
- If it is a constructor then remove `void` (return type)
- If it is a simple method then change the name to something other than `SuperTeam`
See Details about your Error - Compiler Error CS0542:
The members of a class or struct cannot have the same name as the class or struct, unless the member is a constructor
AND (thanks to @Alexei Levenkov)
This error might be caused if you inadvertently put a return type on a constructor, which in effect makes it into an ordinary method.
Problem
I Have this error but i can't identify the error (CS0542) for some reason: member names cannot be the same as their enclosing type Code: ``` class SuperTeam { string SuperTeamName; public SuperTeam() { SuperTeamName = ""; } public void SuperTeam (string nSuperTeamName) { SuperTeamName = nSuperTeamName; } } ```