如何使用 C# 中的 Action, Func,Predicate

https://mp.weixin.qq.com/s/kUb22Qwb8JWIy_mb0nMttA


        static void Main(string[] args)
        {
            Action<string> action = new Action<string>(Display);
            action("Hello!!!");
            Console.Read();
        }
        
        static void Display(string message)
        {
            Console.WriteLine(message);
        }
----------------

        static void Main(string[] args)
        {
            Func<int, double> func = new Func<int, double>(CalculateHra);
            Console.WriteLine(func(50000));
            Console.Read();
        }
        static double CalculateHra(int basic)
        {
            return (double)(basic * .4);
        }
-----------------
        static void Main(string[] args)
        {
            List<Customer> custList = new List<Customer>();
            custList.Add(new Customer { Id = 1, FirstName = "Joydip",
													LastName = "Kanjilal", State = "Telengana", 
													City = "Hyderabad", Address = "Begumpet", 
													Country = "India" });
            custList.Add(new Customer { Id = 2, FirstName = "Steve", 
													LastName = "Jones", State = "OA", 
													City = "New York", 
													Address = "Lake Avenue", Country = "US" });
            Predicate<Customer> hydCustomers = x => x.Id == 1;
            Customer customer = custList.Find(hydCustomers);
            Console.WriteLine(customer.FirstName);
            Console.Read();
        }
---------


作者:spike

分类: Net

创作时间:2023-06-25

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1