private static void Main(string[] args) { //#1 //b //#2 for (int i = 0; i < 5; i++) { employeesList.Add(new Employee(i, $"name{i}", 1000 + i)); } foreach (var item in employeesList) { WriteLine(item.Name); } EmployeeDelegate employeeDelegate = FindLowestSalary; employeeDelegate += FindHighestSalary; employeeDelegate(); //#3 Tuple <string, int, string> personTuple = Tuple.Create("Zhaosheng", 30, "Montreal"); PrintTupleByInterpolation(personTuple); PrintTupleByFormat(personTuple); //#4 Dictionary <int, string> employeesDictionary = new Dictionary <int, string>(); for (int i = 0; i < employeesList.Count; i++) { employeesDictionary.Add(employeesList[i].Id, $"Office Address{i}"); } foreach (var item in employeesDictionary) { WriteLine(item); } //#5 new MyConstraintGenericClass <Employee>(); //new MyConstraintGenericClass<int>(); //#6 int number = 5; WriteLine($"The number {number} is dividable by 3: {number.IsDividableByThree()}"); //#7 HasVowel("asdfe"); //#8 Student student = new Student() { Name = "Zhaosheng", IsGraduated = false }; student.StudentGraduated += RegisterStudentOperation.Graduated; student.IsGraduated = true; ReadKey(); }
static void Main2() { EmployeeDelegate empDel = new EmployeeDelegate(GetEmployee); Employee emp = empDel(); SalesEmployeeDelegate salesEmpDel = new SalesEmployeeDelegate(GetSalesEmployee); SalesEmployee emp2 = salesEmpDel(); }
static void Main3() { EmployeeDelegate emp = new EmployeeDelegate(GetEmployee); Employee emp1 = emp(); EmployeeDelegate empB = new EmployeeDelegate(GetSalesEmployee); //to obtain a derived type you must perform an explicit cast. SalesEmployee emp2 = (SalesEmployee)empB(); }
static void Main(string[] args) { Employee emp = new Employee("Kipkemei", "Oliver", 4); EmployeeDelegate empdel = new EmployeeDelegate(GetEmployee); Employee employee_1 = empdel(); EmployeeDelegate salesEmpDel = new EmployeeDelegate(GetSalesEmployee); SalesEmployee emp_2 = (SalesEmployee)salesEmpDel(); }