stringFunc = () => ""; Func objectF...">

Adding two features?

I just looked at "C # in depth" and came across the following code:

Func<string> stringFunc = () => ""; Func<object> objectFunc = () => new object(); Func<object> combined = objectFunc + stringFunc; 

I'm sure adding two functions in math is pointless, so why does any programmer want to overload operator+ binary functions for functions? This seems to be a great example of why overload operators can be harmful (and I generally support the idea of ​​operator overloading).

  • What does it mean to add two functions in C #? (I'm C # noob, so carry me.)

  • Do you agree with a design error to overload operator+ here?

  • What is better for the syntax to achieve what operator+ here?

+4
source share
2 answers

The delegate1 + delegate2 entry will create a third instance of the delegate, which combines the first two, invoking all the functions in both delegates.
This is primarily intended for events.

Documentation

+3
source

Adding two functions is completely significant in mathematics. When you accept the notion that functions are operators, then the space of all such operators is a linear space (under certain conditions). This is a very productive point of view that provides a lot of useful mathematical insight.

Of course, this is not what is happening here, but I wanted to put you on the mathematical side of your question!

+2
source

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


All Articles