Thomas Carlton
Thomas Carlton

Reputation: 5968

Default value for a function parameter of type Class?

Is it possible to have a default value for a function parameter of type Class ?

Something like this

public sub MyMethod(A as integer, optional B as integer = 0, optional Control as Control = new TextEdit)
End Sub 

I tried this but it gives an error : a constant expression is required

Any ideas please ?

Thanks.

Upvotes: 0

Views: 33

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062820

Optional values must be viable literals. In the case of reference-types (except for string, which has different rules), this means: null (Nothing), or (identically) default(TheType) (whatever that is in VB). That's all.

Upvotes: 1

Related Questions