wingman007 icon

RegularVsLambdas

wingman007 | PRO | 09/25/25 08:38:04 AM UTC (Edited) | 0 ⭐ | 13563 👁️ | Never ⏰ | []
C# |

460 B

|

None

|

0 👍

/

0 👎

// Regular method - complex logic
static int Factorial(int n)
{
    int result = 1;
    for (int i = 2; i <= n; i++)
        result *= i;
    return result;
}
 
// Lambda method - simple expression
static int Square(int x) => x * x;
 
 
// Expression-bodied (no explicit return)
Func<int, int> addOne = x => x + 1;
 
// Statement-bodied (explicit return)
Func<int, int> addOneVerbose = x =>
{
    int y = x + 1;
    return y;  // must return explicitly
};
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎