I am new to C # syntax. I wrote the following class (codebehind for the main page of my site):
public partial class MasterPagePro : System.Web.UI.MasterPage
{
public String pageTitle
{
get
{
if (this.pageTitle == null)
return "";
else
return " - " + this.pageTitle;
}
}
}
However, when I try to access pageTitle, like this in html:
<title>MySite<%=pageTitle%></title>
I get stackoverflow error. Looking at the code, itβs pretty clear that the problem is that the method calls itself recursively, but I donβt know what to write to solve this problem. I could do something like:
public partial class MasterPagePro : System.Web.UI.MasterPage
{
private String _pageTitle
public String pageTitle
{
get
{
if (_pageTitle == null)
return "";
else
return " - " + _pageTitle;
}
set { _pageTitle = value; }
}
}
But it looks like you have a syntax shortcut. What is the right way to do this?
source
share