Why are operator overloads not used more often?

In many scenarios, operator overloading allows you to prove yourself better. Why are they hardly used in C #?

+3
source share
5 answers

They are not used very often, because often it makes no sense to have mathematical operations (which are most operators) for most classes of objects. The semantics of the operations you want tend to differ in some way. You would not use the addition to a bunch of OrderLine objects, for example, when you really need aggregation or grouping.

, , "+" , . "+" , , . , , , , .

, .

+11

, , , , .

- , . , string!= , , , ( ).

+6
+1

, , DSL ( ).
PEG, BNF: .
Lpeg- Lua Nimrod PEG , , .

0

.NET , . , , << >> . , , ++ , .

Therefore, in most scenarios this does not make sense, because unfortunately you do not have access to all operators.

0
source

Source: https://habr.com/ru/post/1729200/


All Articles