Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ✅ Named method – complex logic
- static int Factorial(int n)
- {
- int result = 1;
- for (int i = 2; i <= n; i++)
- result *= i;
- return result;
- }
- // ✅ Named expression-bodied method – simple logic
- static int Square(int x) => x * x;
- // ✅ Anonymous lambda – expression-bodied
- Func<int, int> addOne = x => x + 1;
- // ✅ Anonymous lambda – statement-bodied
- Func<int, int> addOneVerbose = x =>
- {
- int y = x + 1;
- return y; // must return explicitly
- };
Advertisement
Add Comment
Please, Sign In to add comment