'member names cannot be the same as their enclosing type

  • Thread starter Thread starter Nik
  • Start date Start date
N

Nik

I keep getting the following error 'member names cannot be
the same as their enclosing type' with the code below.

public class HelpText
{
private string _textToDisplay;
private string _cssClass;

public string TextToDisplay {
get {return _textToDisplay;}
set {_textToDisplay = value;}
}

public string CssClass {
get {return _cssClass;}
set {_cssClass = value;}
}

public string HelpText()
{
WebAuthorContext authorContext =
WebAuthorContext.Current();

//Check if in edit mode
if (authorContext.Mode ==
WebAuthorContextMode.AuthoringNew || authorContext.Mode ==
WebAuthorContextMode.AuthoringReedit) {
HelpText = "<span
class=\"" + CssClass + "\">" + TextToDisplay + "</span>";
}
} }

any ideas?
 
You declare a constructor for the class HelpText that returns a value - a string. Constructors do not return any type. They just construct the object of the type. You should move the code that returns your constructed string to another method. Although, you can still build the string in the constructor and store it in a member variable.
 
HelpText = "<span
class=\"" + CssClass + "\">" + TextToDisplay + "</span>";

Why are you assigning *HelpText* a string value? HelpText is the name
of your class!

<snip>
 
I can't understand what you're try to do from your code.
What are you trying to do?

- pete
 
Nik said:
I keep getting the following error 'member names cannot be
the same as their enclosing type' with the code below.

The class HelpText may not contain a method named HelpText. Only
constructors may have the same name as their enclosing type.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
Back
Top