Phantom - 5 months ago 28

C# Question

I am having some trouble on understanding some C# Func<...> operators, for example, we have the following snippet:

`Func<int, bool> a = n => n <= 1;`

Func<int, int> b = n => 10;

Func<int, int> c = n => { return n; };

Func<int, int> d = n => a(n)? b(n): n*c(n-1);

Console.WriteLine("{0} {1} {2}", d(1), d(2), d(3));

What is the meaing of

`?`

`:`

`a(n)? b(n)`

`a(n)`

`d`

Answer

To make it more clear, you can interpret

```
n => a(n)? b(n): n*c(n-1);
```

as (given the definitions provided at your question):

```
if (n<=1)
return 10; //b(n)
else
return n*n-1; //n*c(n-1)=n*n
```

Notice that `returns`

are there because of `d=...`