Assignment Operator (=) in Method Definition Argument

See method definition below.

What is called in C #, where the equal sign is in the parameter of the method.

Is this initialization of the default method parameter?

public List<Iabc> MyMethod(out List<Ixyz> faces, Type typeXYZ = null, int flag = -1) { //... //... } 

NOTE. Here Iabc and Ixyz are any interfaces.

+8
c #
source share
3 answers

They are called optional (or named) arguments. MSDN usually explains this well:

Named and Optional Arguments (C # Programming Guide)

+9
source share

When using named arguments, remember that changing the name of the arguments will break the code. (where named parameters are used)

Also, remember that the default value is actually stored at the place of the call , which means that if you change the default value at some point, the code that calls the method and compiled before the change will use the old value . this may not be important in all situations, but it is something to be aware of.

+3
source share

This is an optional argument in C # 4.0

+2
source share

All Articles