simple lambda expressions
using System;
namespace test
{
class Program
{
static void Main(string[] args)
{
Func<bool, int> del = x => x ? 10 : 5;
new ShoppingCart().Process(del);
// can also be
//new ShoppingCart().Process(x => x ? 10 : 5);
// can also be
//new ShoppingCart().Process(
//x =>
//{
// int discount = 0;
// if( x )
// {
// discount = 20;
// }
// else if (DateTime.Now.Hour < 12)
// {
// discount = 5;
// }
// else if (DateTime.Now.Hour < 20)
// {
// discount = 10;
// }
// else
// {
// discount = 15;
// }
// return discount;
//});
}
}
class ShoppingCart
{
public void Process(Func<bool, int> discount)
{
int magicDiscount = discount(false);
int magicDiscount2 = discount(true);
Console.WriteLine(magicDiscount);
Console.WriteLine(magicDiscount2);
Console.ReadLine();
}
}
}
namespace test
{
class Program
{
static void Main(string[] args)
{
Func<bool, int> del = x => x ? 10 : 5;
new ShoppingCart().Process(del);
// can also be
//new ShoppingCart().Process(x => x ? 10 : 5);
// can also be
//new ShoppingCart().Process(
//x =>
//{
// int discount = 0;
// if( x )
// {
// discount = 20;
// }
// else if (DateTime.Now.Hour < 12)
// {
// discount = 5;
// }
// else if (DateTime.Now.Hour < 20)
// {
// discount = 10;
// }
// else
// {
// discount = 15;
// }
// return discount;
//});
}
}
class ShoppingCart
{
public void Process(Func<bool, int> discount)
{
int magicDiscount = discount(false);
int magicDiscount2 = discount(true);
Console.WriteLine(magicDiscount);
Console.WriteLine(magicDiscount2);
Console.ReadLine();
}
}
}