Pergunta

I just browsed through "C# in Depth" and stumbled upon the following code:

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

I'm pretty sure that adding two functions is meaningless in mathematics, so why would any programmer want an overload of the binary operator+ for functions? This seems to be a perfect example of why overloading operators can do harm (and I generally support the idea of operator overloading).

  1. What does it mean to add two functions in C#? (I'm a C# noob, so bear with me.)

  2. Do you agree that it was a design mistake to overload operator+ here?

  3. What would be a better syntactic to achieve whatever it is operator+ does here?

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top