Is the new feature of C# 4.0 – “Optional Parameters” CLS-Compliant?

Optional arguments are “sort-of” CLS-compliant. Methods with optional arguments are legal and can be successfully compiled with the CLSCompliant attribute, but callers of those methods don’t necessarily need to take account of the default parameter values or the optional attribute. (In which case those methods would behave in exactly the same way as standard methods, requiring that all the arguments be stated explicitly at the call site.)

Methods that use default parameters
are allowed under the Common Language
Specification (CLS); however, the CLS
allows compilers to ignore the values
that are assigned to these parameters.
Code that is written for compilers
that ignore default parameter values
must explicitly provide arguments for
each default parameter. To maintain
the behavior that you want across
programming languages, methods that
use default parameters should be
replaced with method overloads that
provide the default parameters.

(Taken from the documentation for “CA1026: Default parameters should not be used”.)

Leave a Comment

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