C# Func 和 Action

public class Tests
    {
        [Test]
        public void Test2()
        {
            DateTime startDate = new DateTime(2022, 10, 1, 0, 0, 0);
            DateTime endDate = startDate.AddMonths(1).AddSeconds(-1);

            var v = Environment.Version;

            var s1 = new Sword2() { Damage = 10000, Durability = 10000 };

            var s2 = s1 with { Damage = 10001 };

            var s3 = new Sword2() { Damage = 10000, Durability = 10000 };

            Sword s4 = new(100, 100);

            if (s1.Aggressivity is null or { Length: 0 })
            {
                Console.WriteLine($"{nameof(s1.Aggressivity)} is IsNullOrEmpty");
            }

            if (s1.Aggressivity is not null and { Length: > 0 })
            {
                if (s1.Aggressivity[0] is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z') or '.')
                {
                }
            }

            switch (s1.Damage)
            {

                case >= 0 and < 100:
                    break;
                case >= 100 and < 1000:
                    break;
                case >= 1000 and < 100001:
                    break;
            }

            Expression> expression1 = static i => i > 1;

            Func exp = (x) => x;
            var result = exp("Hello world");

            Func exp1 = (x, y) => x * y;
            var result1 = exp1(0, 1);
            result1 = exp1(1, 10);

            Action> exp2 = (x, y, z) => { z.Add(x + y); };

            var list = new List();
            exp2(1, 2, list);
        }

        record class Sword(int Damage, int Durability);

        record class Sword2
        {
            public int Damage { get; set; }
            public int Durability { get; set; }
            public string Aggressivity { get; set; }
        }

    }

你可能感兴趣的:(c#,java,开发语言)