C# 4.0: Can I use a Color as an optional parameter with a default value? [duplicate]

I’ve run into this as well and the only workaround I’ve found is to use nullables.

public void log(String msg, Color? c = null)
{
    loggerText.ForeColor = c ?? Color.Black;
    loggerText.AppendText("\n" + msg);
}

Other possible syntax is:

loggerText.ForeColor = c.GetValueOrDefault(Color.Black);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)