Student[] students; //学生信息列表

        #endregion Fields

        #region Constructors

        public StudentTable()
        {
            students = new Student[8];                      //创建学生信息表
            students[0] = new Student() { Number = 20120001, Name = "张三", Sex = "男" };
            students[1] = new Student() { Number = 20120002, Name = "李四", Sex = "女" };
            students[2] = new Student() { Number = 20120003, Name = "王五", Sex = "男" };
            students[3] = new Student() { Number = 20120004, Name = "赵六", Sex = "女" };
            students[4] = new Student() { Number = 20120005, Name = "钱七", Sex = "男" };
            students[5] = new Student() { Number = 20120006, Name = "孙三", Sex = "女" };
        }
예제 #2
0
 private static void ShowStudent(Student student, EventArgs eventArgs) => Console.WriteLine(student);
 //显示男生信息
 static void Display(Student student)
 {
     if (student.Sex == "男")
     Console.WriteLine("学号:{0}\t姓名:{1}\t性别:{2}",
     student.Number, student.Name, student.Sex);
 }
예제 #4
0
        static void Main(string[] args)
        {
            Reactions react = new Reactions();
            Tourniquet tour = new Tourniquet(react.ReactOnGoodCard, react.ReactOnBadCard);
            Building SecondBuilding = new Building("Кремлевская 35", tour);
            Card card = new Card(7);
            Student Linar = new Student("Linar", card);

            tour.VerifyCard(card);
            Console.ReadLine();
        }
예제 #5
0
        static void Main(string[] args)
        {
            List <Student> students = new List <Student>
            {
                new Student()
                {
                    Id = 1, Name = "John", Grade = 7, Credits = 5
                },
                new Student()
                {
                    Id = 2, Name = "Jelly", Grade = 9, Credits = 45
                },
                new Student()
                {
                    Id = 3, Name = "Jannie", Grade = 7, Credits = 25
                },
                new Student()
                {
                    Id = 4, Name = "Jolly", Grade = 8, Credits = 15
                }
            };



            IsPromotable delegatePromotable = new IsPromotable(Condition);

            Student.PromoteStudent(students, delegatePromotable);

            // CAN BE REDUCED INTO 1 LINE USING LAMPDA
            //Student.PromoteStudent(students, s=>s.Grade > 8);



            // Invoking a normal method
            var normalMethodInvokeResult = NormalMethod(2);

            // Create an instance of the delegate
            var normalMethodDelegate = new Manipulate(NormalMethod);
            var normalResult         = normalMethodDelegate(3);

            // Anonymous method is a a delegate() { } and it returns a delegate
            Manipulate anonymousMethodDelegate = delegate(int a) { return(a * 2); };
            var        anonymousResult         = anonymousMethodDelegate(3);

            // Lambda expressions are anything with => and a left/right value
            // They can return a delegate (so a method that can be invoked)
            // or an Expression of a delegate (so it can be compiled and then executed)
            Manipulate lambaDelegate = a => a * 2;
            var        lambaResult   = lambaDelegate(5);

            // Nicer way to write a lamba
            Manipulate nicerLambaDelegate = (a) => { return(a * 2); };
            var        nicerLambaResult   = nicerLambaDelegate(6);

            // Lamba can return an Expression
            Expression <Manipulate> expressionLambda = a => a * 2;

            // An Action is just a delegate with no return type and optional input
            Action       actionDelegate  = () => { lambaDelegate(2); };
            Action <int> action2Delegate = (a) => { var b = a * 2; };

            // A Func is just a delegate with a return type
            Func <int> myFunc = () => 2;

            // Replace Manipulate with a Func
            Func <int, int> funcDelegate = a => a * 2;
            var             funcResult   = funcDelegate(5);

            // Mimic the FirstOrDefault Linq expression
            var items    = new List <string>(new[] { "a", "b", "c", "d", "e", "f", "g" });
            var itemInts = Enumerable.Range(1, 10).ToList();

            // Calling the nuilt in Linq FirstOrDefault
            var foundItem = items.FirstOrDefault(item => item == "c");

            // Calling our version
            var foundItem2 = items.GetFirstOrDefaultCustom(item => item == "c");
            var foundItem3 = itemInts.GetFirstOrDefaultCustom(item => item > 4);

            Console.ReadKey();
        }
예제 #6
0
 //////////THE CONDITION IS DYNAMICALLY PASSED IN NOT HARD CODED//////////////
 static bool Condition(Student student)
 {
     return(student.Grade > 8 ? true : false);
 }