MSDN talks about advanced options for Visual Basic
For each optional parameter, you must specify a constant expression as the default value for this parameter. If the expression is Nothing, the default value for the value data type is used as the default value for the parameter.
So you cannot use this syntax, instead you can write something like this
Private Sub Test(a As Integer, Optional c As Color = Nothing) If c = Nothing Then c = Color.Black ' your default color' End If ...... End Sub
The same code written in C #, the following
private void Test(int a, Color c = default(Color)) { if (c.IsEmpty) c = Color.Black; }
In C #, you cannot check the type of value (e.g. color, dot, size, etc.) with a null value. These types are never null, but they have a default value for type- (for example, 0 for integers), so if you need to pass an optional parameter for the type of value, you can create it with a new keyword with values ββthat you would like to use the default value or use the default keyword and let the platform decide which value is the default value for the type. If you let the platform choose, the IsEmpty property will be true.
Steve
source share