Pritesh
Pritesh

Reputation: 3288

Assignment operator (=) in argument of Method Definition

See below method definition.

What is it called in C# where the equals sign is in method parameter.

Does it default method parameter initialization??

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

NOTE: Here Iabc and Ixyz are any Interfaces.

Upvotes: 8

Views: 8354

Answers (3)

aL3891
aL3891

Reputation: 6275

When using named arguments, be aware that changing argument names will break code. (where named parameters are used)

Also, remember that the default value is actually stored in the call site meaning that if you at some later point change the default value, code that is calling the method and was compiled before the change, will still use the old value. it might not matter in all situations but its something to be aware of.

Upvotes: 4

Matti Virkkunen
Matti Virkkunen

Reputation: 65126

They're called optional (or named) arguments. MSDN usually has these things explained pretty well:

Named and Optional Arguments (C# Programming Guide)

Upvotes: 10

devdigital
devdigital

Reputation: 34349

That's an optional argument in C# 4.0

Upvotes: 2

Related Questions