0
Why colons and not equals?
In the expression int res = Area(w: 5, h: 8); , why colon and not equal symbol?
2 ответов
+ 4
We would need a reference to w and h to be able to use the equals sign here. Since that would be assigning h and w to the value of whatever is on the opposite side of the equals sign. We cannot assign them without a reference. So instead they use a colon to indicate which variable you are referring to when calling the function. It is not mandatory, you could just write Area(5,8); Although if you don't write which variable you are referring to, the order matters.
If I did Area(8,5); 8 would be the width, assuming the function was written like this:
int Area(int w, int h){}
0
this called named parameters, and that's it's syntax.
you can read more here:
https://www.dotnetperls.com/named-parameters