I currently am making a small application where a user will enter their ID which needs to be in a certain format. When entered in the wrong format, different output errors are produced.
I currently output errors like this:
public void errorLogger(string error)
{
errors += error + Environment.NewLine + "<br>";
}
I have read that using +=
is not a great operator to use. Alternatively I have thought this may be better:
public void errorLogger(string key, string err)
{
if(!String.IsNullOrEmpty(err))
output.Add(key, err);
}
but then I basically do the same thing later:
string keys = "";
foreach (KeyValuePair<string, string> entry in core.errorLogger())
{
keys += entry.Key + ": " + entry.Value + "<br>";
}
Is there a cleaner way to output errors? The output is injected under the submit button into:
errorSpan.InnerHtml = (keys);
This is what I ended up using going off of Charles' response to AWinkle
public void logError(string err, string desc)
{
if(!String.IsNullOrEmpty(desc))
errors.AppendFormat("{0,10}: {1}<br>", err, desc);
}
public string getErrors()
{
return errors.ToString();
}
Then :
errorspan.InnerHtml = (core.getErrors());