Error: Member names cannot be the save as their enclosing type
Possible Cause: Unkowingly I declare Method name, same as class name, which pops-up this error. Logically its out of blue to think, declaring method name as class name as it is constructor, but may be because of nature of application i have declare Class Name as Method Name and runs into Error: "Member names cannot be the save as their enclosing type".
Cause of Error:
public class MyClass
{
//Declaring Method Same as Class Name
//Note: its not constructor, constructor don't have return type.
public void MyClass()
{
}
}
Solution to Error:
public class MyClass
{
//Change Method Name to Something else
public void MyMethod()
{
}
}
4 comments:
What if you actually want to make a constructor?
Remove the value before the name (usually void or int or string etc)
Constructors have no return types so check the syntax again.
e.g.
public class myClass
{
public myClass()
{
}
}
Chris,
Thanks :) I am knowing that constructor have no return type, but have you tried reading the whole description, which states, mistakenly i have declare METHOD name as CLASS name, which cause this whole confusion and I ran into error.
i have a question along the same line.. i can't figure out why i get the same error in this program section.
public class Loan
{
private double loanSum, APR, bal, prin, monthsInt, totIntPaid, amountPaid;
private int numberPay;
public Loan()
{
}
public Loan(double Loans, double intRate, int yrs)
{
loanSum = Loans;
if (intRate < 1)
APR = intRate;
numberPay = 12 * yrs;
totIntPaid = 0;
}
@Skylar
You should not receive this error, check the whole class code, you might have declare Method Name Loan in your Loan Class.
Post a Comment