I confused: is there any way to simplify that code?
private void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(pnlMain.Title) && string.IsNullOrWhiteSpace(Title))
pnlMain.Title = DefaultTitle;
else if (string.IsNullOrWhiteSpace(Title))
pnlMain.Title = DefaultTitle;
else
pnlMain.Title = Title;
}
If you draw up a logic table for it you should be able to work it out… Have columns for true and false for
pnlMain.Titlebeing null or whitespace and rows forTitlebeing null or whitespace and then in each cell mark whether you use theDefaultTitleorTitlewhen you go through the above logic.You should get the result that it doesn’t matter what pnlMain.Title is.
So that code is the same as:
You can probably see it when you know the answer because in your code your first two checks are the same except with and without pnlMain.Title being checked as well and the same outcome.
From looking at what you might be trying to do you might in fact be wanting to do this:
The above code will only change pnlMain.Title if it is null or white space and will use Title if that is not null or whitespace and otherwise fall back to DefaultTitle. This seems like more what I’d expect you to be wanting to do…