├── .gitignore ├── README.md ├── Section02-Class ├── Assignment1.md ├── Assignment1Solution │ ├── CMS.Application │ │ ├── CMS.Application.csproj │ │ └── Program.cs │ └── CMS.UI.Models │ │ ├── CMS.UI.Models.csproj │ │ ├── Course.cs │ │ ├── CourseSubject.cs │ │ ├── Staff.cs │ │ └── Student.cs └── CMS │ ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs │ └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── Staff.cs │ └── Student.cs ├── Section03-ClassFields ├── Assignment1.md ├── Assignment1Solution │ ├── CMS.Application │ │ ├── CMS.Application.csproj │ │ └── Program.cs │ └── CMS.UI.Models │ │ ├── CMS.UI.Models.csproj │ │ ├── Course.cs │ │ ├── CourseSubject.cs │ │ ├── Staff.cs │ │ └── Student.cs └── CMS │ ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs │ └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── Course.cs │ ├── CourseSubject.cs │ ├── Staff.cs │ └── Student.cs ├── Section04-ClassMethods ├── Assignment1.md ├── Assignment1Solution │ ├── CMS.Application │ │ ├── CMS.Application.csproj │ │ └── Program.cs │ ├── CMS.UI.Display │ │ ├── CMS.UI.Display.csproj │ │ └── Display.cs │ └── CMS.UI.Models │ │ ├── CMS.UI.Models.csproj │ │ ├── Course.cs │ │ ├── CourseSubject.cs │ │ ├── Staff.cs │ │ └── Student.cs └── CMS │ ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs │ ├── CMS.UI.Display │ ├── CMS.UI.Display.csproj │ └── Display.cs │ └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── Course.cs │ ├── CourseSubject.cs │ ├── Staff.cs │ └── Student.cs ├── Section05-Interface ├── Assignment1.md ├── Assignment1Solution │ ├── CMS.Application │ │ ├── CMS.Application.csproj │ │ └── Program.cs │ ├── CMS.UI.Display │ │ ├── CMS.UI.Display.csproj │ │ └── Display.cs │ └── CMS.UI.Models │ │ ├── CMS.UI.Models.csproj │ │ ├── CSCourse.cs │ │ ├── Course.cs │ │ ├── CourseSubject.cs │ │ ├── ElectronicsCourse.cs │ │ ├── ICourse.cs │ │ ├── IStudent.cs │ │ ├── Staff.cs │ │ └── Student.cs └── CMS │ ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs │ ├── CMS.UI.Display │ ├── CMS.UI.Display.csproj │ └── Display.cs │ └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── CSCourse.cs │ ├── Course.cs │ ├── CourseSubject.cs │ ├── ElectronicsCourse.cs │ ├── ICourse.cs │ ├── IStudent.cs │ ├── Staff.cs │ └── Student.cs ├── Section06-Inheritance ├── Assignment1.md ├── Assignment1Solution │ ├── CMS.Application │ │ ├── CMS.Application.csproj │ │ └── Program.cs │ ├── CMS.UI.Display │ │ ├── CMS.UI.Display.csproj │ │ ├── Contractor.cs │ │ └── Display.cs │ └── CMS.UI.Models │ │ ├── CMS.UI.Models.csproj │ │ ├── CSCourse.cs │ │ ├── Contracts │ │ ├── ICourse.cs │ │ └── IStudent.cs │ │ ├── Course.cs │ │ ├── CourseSubject.cs │ │ ├── ElectronicsCourse.cs │ │ ├── Person.cs │ │ ├── Staff.cs │ │ └── Student.cs └── CMS │ ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs │ ├── CMS.UI.Display │ ├── CMS.UI.Display.csproj │ ├── Contractor.cs │ └── Display.cs │ └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── CSCourse.cs │ ├── Contracts │ ├── ICourse.cs │ └── IStudent.cs │ ├── Course.cs │ ├── CourseSubject.cs │ ├── ElectronicsCourse.cs │ ├── Person.cs │ ├── Staff.cs │ └── Student.cs └── Section07-Polymorphism ├── Assignment1.md ├── Assignment1Solution ├── CMS.Application │ ├── CMS.Application.csproj │ └── Program.cs ├── CMS.UI.Display │ ├── CMS.UI.Display.csproj │ ├── Contractor.cs │ └── Display.cs └── CMS.UI.Models │ ├── CMS.UI.Models.csproj │ ├── CSCourse.cs │ ├── Contracts │ ├── ICourse.cs │ └── IStudent.cs │ ├── Course.cs │ ├── CourseSubject.cs │ ├── ElectronicsCourse.cs │ ├── Hobby.cs │ ├── Person.cs │ ├── Staff.cs │ └── Student.cs └── CMS ├── CMS.Application ├── CMS.Application.csproj └── Program.cs ├── CMS.UI.Display ├── CMS.UI.Display.csproj ├── Contractor.cs └── Display.cs └── CMS.UI.Models ├── CMS.UI.Models.csproj ├── CSCourse.cs ├── Contracts ├── ICourse.cs └── IStudent.cs ├── Course.cs ├── CourseSubject.cs ├── ElectronicsCourse.cs ├── Hobby.cs ├── Person.cs ├── Staff.cs └── Student.cs /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj 3 | .vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C# Intermediate Course Repo 2 | C# Intermediate: Learn OOP in C# with .NET Core, a guide to learning the C# Object-Oriented Programming (OOP) concepts for starting a C# programming career. 3 | 4 | ## Repository for the C# Intermediate OOP Course 5 | This repo covers the following: 6 | * Demo 7 | * Assignment (ready-made projects to start working) 8 | * Assignment Solutions 9 | 10 | ## Enroll in this course with 90% discount 11 | Click this link to enroll in this course: 12 | https://codewithpraveen.com/csharp-oop-course-coupon 13 | -------------------------------------------------------------------------------- /Section02-Class/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | 1. For the CMS system, define Course type in a new file Course.cs in CMS.UI.Models assembly. 3 | 4 | 2. Create an object instance named computerScience of type Course class in CMS.Application assembly. 5 | 6 | 3. Create CourseSubject type in a new file CourseSubject.cs in CMS.UI.Models assembly. 7 | -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Exe 9 | netcoreapp3.1 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Models; 3 | 4 | namespace CMS.Application 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Student student = new Student(); 11 | Staff staff = new Staff(); 12 | 13 | Course computerScience = new Course(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Course 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | public Staff() 6 | { 7 | 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Section02-Class/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | public Student() 8 | { 9 | // All initializations goes here. 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section02-Class/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Exe 9 | netcoreapp3.1 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Section02-Class/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Models; 3 | 4 | namespace CMS.Application 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Student student = new Student(); 11 | Staff staff = new Staff(); 12 | 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Section02-Class/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section02-Class/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | public Staff() 6 | { 7 | 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Section02-Class/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | public Student() 8 | { 9 | // All initializations goes here. 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | 1. For the Course class, add the following fields, create an instance of Course class, assign the field values, and finally print the same to the console. 3 | * CourseId of type integer with public access. 4 | * CourseName of type string with public access. 5 | 6 | 2. For the CourseSubject class, add the following fields: 7 | * Id of type integer with public access 8 | * SubjectName of type string with public access 9 | 10 | 3. Add a static field to store MaxSubjects in Course class and assign a default value of 8. 11 | -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Exe 9 | netcoreapp3.1 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Models; 3 | 4 | namespace CMS.Application 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | // Object instantiation 11 | Student student = new Student(); 12 | Staff staff = new Staff(); 13 | 14 | Course computerScience = new Course(); 15 | computerScience.CourseId = 201; 16 | computerScience.CourseName = "ComputerScience"; 17 | Console.WriteLine(computerScience.CourseId); 18 | Console.WriteLine(computerScience.CourseName); 19 | 20 | // Field assignment 21 | student.FirstName = "John"; 22 | Console.WriteLine(student.FirstName); 23 | 24 | // Direct initialization 25 | Student student2 = new Student() 26 | { 27 | FirstName = "John", 28 | LastName = "McCarter", 29 | StudentId = 10001 30 | }; 31 | 32 | // readonly variable 33 | //student2.MaxEnrolledCourses = 6; 34 | 35 | // Static variables 36 | Student.MaxBooksAllowed = 8; 37 | Console.WriteLine(Student.MaxBooksAllowed); 38 | 39 | // Value and reference types 40 | Console.WriteLine("Value and reference types"); 41 | int a = 10; 42 | Console.WriteLine(a); 43 | int b = a; 44 | b = 20; 45 | Console.WriteLine(a); 46 | 47 | student.FirstName = "John"; 48 | Console.WriteLine(student.FirstName); 49 | student2 = student; 50 | student2.FirstName = "Ashok"; 51 | Console.WriteLine(student.FirstName); 52 | 53 | // Access modifiers 54 | staff.FirstName = "Staff1"; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Course 4 | { 5 | public int CourseId; 6 | public string CourseName; 7 | 8 | public static int MaxSubjects = 8; 9 | } 10 | } -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | public string FirstName; 6 | public Staff() 7 | { 8 | FirstName = "Staff1"; 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Section03-ClassFields/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | // Class fields 8 | public string FirstName = default; 9 | public string LastName = string.Empty; 10 | public int StudentId = 10000; 11 | 12 | // const field 13 | //public const int MaxEnrolledCourses = 3; 14 | 15 | // readonly field 16 | public readonly int MaxEnrolledCourses = 3; 17 | 18 | // Static field 19 | public static int MaxBooksAllowed = 6; 20 | 21 | // Student constructor 22 | public Student() 23 | { 24 | // All initializations goes here. 25 | int TotalCourses = 6; 26 | MaxEnrolledCourses = TotalCourses; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Exe 9 | netcoreapp3.1 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Models; 3 | 4 | namespace CMS.Application 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | // Object instantiation 11 | Student student = new Student(); 12 | Staff staff = new Staff(); 13 | 14 | Course computerScience = new Course(); 15 | 16 | // Field assignment 17 | student.FirstName = "John"; 18 | Console.WriteLine(student.FirstName); 19 | 20 | // Direct initialization 21 | Student student2 = new Student() 22 | { 23 | FirstName = "John", 24 | LastName = "McCarter", 25 | StudentId = 10001 26 | }; 27 | 28 | // readonly variable 29 | //student2.MaxEnrolledCourses = 6; 30 | 31 | // Static variables 32 | Student.MaxBooksAllowed = 8; 33 | Console.WriteLine(Student.MaxBooksAllowed); 34 | 35 | // Value and reference types 36 | Console.WriteLine("Value and reference types"); 37 | int a = 10; 38 | Console.WriteLine(a); 39 | int b = a; 40 | b = 20; 41 | Console.WriteLine(a); 42 | 43 | student.FirstName = "John"; 44 | Console.WriteLine(student.FirstName); 45 | student2 = student; 46 | student2.FirstName = "Ashok"; 47 | Console.WriteLine(student.FirstName); 48 | 49 | // Access modifiers 50 | staff.FirstName = "Staff1"; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Course 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | public string FirstName; 6 | public Staff() 7 | { 8 | FirstName = "Staff1"; 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Section03-ClassFields/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | // Class fields 8 | public string FirstName = default; 9 | public string LastName = string.Empty; 10 | public int StudentId = 10000; 11 | 12 | // const field 13 | //public const int MaxEnrolledCourses = 3; 14 | 15 | // readonly field 16 | public readonly int MaxEnrolledCourses = 3; 17 | 18 | // Static field 19 | public static int MaxBooksAllowed = 6; 20 | 21 | // Student constructor 22 | public Student() 23 | { 24 | // All initializations goes here. 25 | int TotalCourses = 6; 26 | MaxEnrolledCourses = TotalCourses; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | 1. For the Course class, add the following: 3 | * A private field “subjects” of type List to store the list of subjects for the course. 4 | * Expose a public property Subjects with only a getter that returns this “subjects” list. 5 | * AddSubject method which accepts CourseSubject as a parameter which returns none. It should add the subject to the subjects list. 6 | * RemoveSubject method which accepts CourseSubject as a parameter which returns none. It should remove the course subject from the subjects list. 7 | 8 | 2. For the Course class, add an overloaded AddSubject() method that accepts a list of CourseSubjects and adds them to the “subjects” collection. 9 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Display; 3 | using CMS.UI.Models; 4 | 5 | namespace CMS.Application 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Object instantiation 12 | Student student = new Student(); 13 | Staff staff = new Staff(); 14 | 15 | // Field assignment 16 | student.FirstName = "John"; 17 | Console.WriteLine(student.FirstName); 18 | 19 | // Direct initialization 20 | Student student2 = new Student() 21 | { 22 | FirstName = "John", 23 | LastName = "McCarter", 24 | StudentId = 10001 25 | }; 26 | 27 | // readonly variable 28 | //student2.MaxEnrolledCourses = 6; 29 | 30 | // Static variables 31 | Student.MaxBooksAllowed = 8; 32 | Console.WriteLine(Student.MaxBooksAllowed); 33 | 34 | // Value and reference types 35 | Console.WriteLine("Value and reference types"); 36 | int a = 10; 37 | Console.WriteLine(a); 38 | int b = a; 39 | b = 20; 40 | Console.WriteLine(a); 41 | 42 | student.FirstName = "John"; 43 | Console.WriteLine(student.FirstName); 44 | student2 = student; 45 | student2.FirstName = "Ashok"; 46 | Console.WriteLine(student.FirstName); 47 | 48 | // Access modifiers 49 | staff.FirstName = "Staff1"; 50 | 51 | // Methods 52 | Student student3 = new Student() 53 | { 54 | FirstName = "John", 55 | LastName = "McCarter", 56 | StudentId = 10003 57 | }; 58 | Console.WriteLine(student3.GetId()); 59 | Console.WriteLine(student3.GetFullName()); 60 | 61 | // Constructor and Destructor 62 | Student student4 = new Student(); 63 | Student student5 = new Student(10004, "Ashok", "Kumar"); 64 | 65 | // Properties 66 | Staff staff3 = new Staff(); 67 | string name = staff3.FirstName; 68 | name = staff3.LastName; 69 | int iD = staff3.Id; 70 | //staff3.Id = 10005; 71 | 72 | // Types of passing parameters 73 | decimal electiveFees = 5000; 74 | decimal roughFees = 5000; 75 | decimal finalFees = 5000; 76 | Console.WriteLine(electiveFees); 77 | Console.WriteLine(roughFees); 78 | Console.WriteLine(finalFees); 79 | 80 | staff3.CalculateFees(electiveFees, ref roughFees, out finalFees); 81 | 82 | Console.WriteLine("After calculating fees"); 83 | Console.WriteLine(electiveFees); 84 | Console.WriteLine(roughFees); 85 | Console.WriteLine(finalFees); 86 | 87 | // Method overloading 88 | staff3.UpdateInfo("John"); 89 | staff3.UpdateInfo("John", "McCarter"); 90 | 91 | // Static class 92 | Display.Show("Hello"); 93 | 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Course 6 | { 7 | public int CourseId; 8 | public string CourseName; 9 | public static int MaxSubjects = 8; 10 | private List subjects = new List(); 11 | 12 | public List Subjects 13 | { 14 | get 15 | { 16 | return subjects; 17 | } 18 | 19 | private set 20 | { 21 | subjects = value; 22 | } 23 | } 24 | 25 | public void AddSubject(CourseSubject subject) 26 | { 27 | subjects.Add(subject); 28 | } 29 | 30 | public void AddSubject(List subjectCollection) 31 | { 32 | subjects.AddRange(subjectCollection); 33 | } 34 | 35 | public void RemoveSubject(CourseSubject subject) 36 | { 37 | Subjects.Remove(subject); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | private string firstName; 6 | public string FirstName 7 | { 8 | get 9 | { 10 | return firstName; 11 | } 12 | set 13 | { 14 | firstName = value; 15 | } 16 | } 17 | 18 | public string LastName { get; set; } = string.Empty; 19 | 20 | public int Id { get; private set; } 21 | 22 | public Staff() 23 | { 24 | FirstName = "Staff1"; 25 | } 26 | 27 | public void CalculateFees(decimal electiveFees, ref decimal roughFees, 28 | out decimal finalFees) 29 | { 30 | electiveFees = 10000; 31 | roughFees = 10000; 32 | finalFees = 10000; 33 | } 34 | 35 | // public void UpdateInfo(string firstName) 36 | // { 37 | // FirstName = firstName; 38 | // } 39 | 40 | public void UpdateInfo(string firstName, string lastName = "") 41 | { 42 | FirstName = firstName; 43 | LastName = lastName; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | // Class fields 8 | public string FirstName = default; 9 | public string LastName = string.Empty; 10 | public int StudentId = 10000; 11 | 12 | // const field 13 | //public const int MaxEnrolledCourses = 3; 14 | 15 | // readonly field 16 | public readonly int MaxEnrolledCourses = 3; 17 | 18 | // Static field 19 | public static int MaxBooksAllowed = 6; 20 | 21 | // Student constructor 22 | public Student() 23 | { 24 | Console.WriteLine("Calling Student.Student()"); 25 | 26 | // All initializations goes here. 27 | int TotalCourses = 6; 28 | MaxEnrolledCourses = TotalCourses; 29 | } 30 | 31 | public Student(int id, string firstName, string lastName) 32 | { 33 | Console.WriteLine("Calling Student.Student(int, string, string)"); 34 | 35 | StudentId = id; 36 | FirstName = firstName; 37 | LastName = lastName; 38 | } 39 | 40 | ~Student() 41 | { 42 | // Cleanup code goes here. 43 | 44 | } 45 | 46 | public int GetId() 47 | { 48 | return StudentId; 49 | } 50 | 51 | public string GetFullName() 52 | { 53 | return $"{FirstName} {LastName}"; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Display; 3 | using CMS.UI.Models; 4 | 5 | namespace CMS.Application 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | // Object instantiation 12 | Student student = new Student(); 13 | Staff staff = new Staff(); 14 | 15 | // Field assignment 16 | student.FirstName = "John"; 17 | Console.WriteLine(student.FirstName); 18 | 19 | // Direct initialization 20 | Student student2 = new Student() 21 | { 22 | FirstName = "John", 23 | LastName = "McCarter", 24 | StudentId = 10001 25 | }; 26 | 27 | // readonly variable 28 | //student2.MaxEnrolledCourses = 6; 29 | 30 | // Static variables 31 | Student.MaxBooksAllowed = 8; 32 | Console.WriteLine(Student.MaxBooksAllowed); 33 | 34 | // Value and reference types 35 | Console.WriteLine("Value and reference types"); 36 | int a = 10; 37 | Console.WriteLine(a); 38 | int b = a; 39 | b = 20; 40 | Console.WriteLine(a); 41 | 42 | student.FirstName = "John"; 43 | Console.WriteLine(student.FirstName); 44 | student2 = student; 45 | student2.FirstName = "Ashok"; 46 | Console.WriteLine(student.FirstName); 47 | 48 | // Access modifiers 49 | staff.FirstName = "Staff1"; 50 | 51 | // Methods 52 | Student student3 = new Student() 53 | { 54 | FirstName = "John", 55 | LastName = "McCarter", 56 | StudentId = 10003 57 | }; 58 | Console.WriteLine(student3.GetId()); 59 | Console.WriteLine(student3.GetFullName()); 60 | 61 | // Constructor and Destructor 62 | Student student4 = new Student(); 63 | Student student5 = new Student(10004, "Ashok", "Kumar"); 64 | 65 | // Properties 66 | Staff staff3 = new Staff(); 67 | string name = staff3.FirstName; 68 | name = staff3.LastName; 69 | int iD = staff3.Id; 70 | //staff3.Id = 10005; 71 | 72 | // Types of passing parameters 73 | decimal electiveFees = 5000; 74 | decimal roughFees = 5000; 75 | decimal finalFees = 5000; 76 | Console.WriteLine(electiveFees); 77 | Console.WriteLine(roughFees); 78 | Console.WriteLine(finalFees); 79 | 80 | staff3.CalculateFees(electiveFees, ref roughFees, out finalFees); 81 | 82 | Console.WriteLine("After calculating fees"); 83 | Console.WriteLine(electiveFees); 84 | Console.WriteLine(roughFees); 85 | Console.WriteLine(finalFees); 86 | 87 | // Method overloading 88 | staff3.UpdateInfo("John"); 89 | staff3.UpdateInfo("John", "McCarter"); 90 | 91 | // Static class 92 | Display.Show("Hello"); 93 | 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Course 4 | { 5 | public int CourseId; 6 | public string CourseName; 7 | public static int MaxSubjects = 8; 8 | } 9 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | private string firstName; 6 | public string FirstName 7 | { 8 | get 9 | { 10 | return firstName; 11 | } 12 | set 13 | { 14 | firstName = value; 15 | } 16 | } 17 | 18 | public string LastName { get; set; } = string.Empty; 19 | 20 | public int Id { get; private set; } 21 | 22 | public Staff() 23 | { 24 | FirstName = "Staff1"; 25 | } 26 | 27 | public void CalculateFees(decimal electiveFees, ref decimal roughFees, 28 | out decimal finalFees) 29 | { 30 | electiveFees = 10000; 31 | roughFees = 10000; 32 | finalFees = 10000; 33 | } 34 | 35 | // public void UpdateInfo(string firstName) 36 | // { 37 | // FirstName = firstName; 38 | // } 39 | 40 | public void UpdateInfo(string firstName, string lastName = "") 41 | { 42 | FirstName = firstName; 43 | LastName = lastName; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Section04-ClassMethods/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | // Class fields 8 | public string FirstName = default; 9 | public string LastName = string.Empty; 10 | public int StudentId = 10000; 11 | 12 | // const field 13 | //public const int MaxEnrolledCourses = 3; 14 | 15 | // readonly field 16 | public readonly int MaxEnrolledCourses = 3; 17 | 18 | // Static field 19 | public static int MaxBooksAllowed = 6; 20 | 21 | // Student constructor 22 | public Student() 23 | { 24 | Console.WriteLine("Calling Student.Student()"); 25 | 26 | // All initializations goes here. 27 | int TotalCourses = 6; 28 | MaxEnrolledCourses = TotalCourses; 29 | } 30 | 31 | public Student(int id, string firstName, string lastName) 32 | { 33 | Console.WriteLine("Calling Student.Student(int, string, string)"); 34 | 35 | StudentId = id; 36 | FirstName = firstName; 37 | LastName = lastName; 38 | } 39 | 40 | ~Student() 41 | { 42 | // Cleanup code goes here. 43 | 44 | } 45 | 46 | public int GetId() 47 | { 48 | return StudentId; 49 | } 50 | 51 | public string GetFullName() 52 | { 53 | return $"{FirstName} {LastName}"; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | For the Student class, do the following: 3 | 1. Make it implement the IStudent interface. 4 | 5 | 2. Move FirstName and LastName fields to the IStudent interface as properties with a getter and a setter. 6 | 7 | 3. Implicitly implement FirstName and LastName properties in the Student class. 8 | 9 | 4. Provide default implementation for the GetFullName method in the IStudent interface that returns FirstName and LastName together. Once done, delete the existing implementation for that method from the Student class. 10 | 11 | 5. Create a new instance of IStudent in CMS.Application project, assign values for FirstName and LastName, followed by printing the result of GetFullName to the console. 12 | 13 | 6. Create a static method WhoAmI() in the IStudent interface that returns “Student” as the value. Access this static method from the console application and print the result. 14 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Display; 3 | using CMS.UI.Models; 4 | 5 | namespace CMS.Application 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | IStudent student = new Student(); 12 | student.FirstName = "David"; 13 | student.LastName = "Smith"; 14 | Console.WriteLine(student.GetFullName()); 15 | 16 | Console.WriteLine(IStudent.WhoAmI()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class CSCourse : ICourse 6 | { 7 | public int TotalDurationInDays { get; set; } 8 | public List Subjects => throw new System.NotImplementedException(); 9 | 10 | public void AddSubject(CourseSubject subject) 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | 15 | public void AddSubject(List subjectsList) 16 | { 17 | throw new System.NotImplementedException(); 18 | } 19 | 20 | public void RemoveSubject(CourseSubject subject) 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = null; 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public void AddSubject(CourseSubject subject) 22 | { 23 | subjects.Add(subject); 24 | } 25 | 26 | public void RemoveSubject(CourseSubject subject) 27 | { 28 | subjects.Remove(subject); 29 | } 30 | 31 | public void AddSubject(List subjectsList) 32 | { 33 | subjects.AddRange(subjectsList); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class ElectronicsCourse : ICourse 6 | { 7 | List ICourse.Subjects => throw new System.NotImplementedException(); 8 | 9 | int ICourse.TotalDurationInDays { get => throw new System.NotImplementedException(); 10 | set => throw new System.NotImplementedException(); } 11 | 12 | void ICourse.AddSubject(CourseSubject subject) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | 17 | void ICourse.AddSubject(List subjectsList) 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | 22 | void ICourse.RemoveSubject(CourseSubject subject) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | static int MaxBooksAllowed = 6; 8 | 9 | string GetFullName() 10 | { 11 | return $"{FirstName} {LastName}"; 12 | } 13 | static string WhoAmI() 14 | { 15 | return "Student"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | private string firstName; 6 | public string FirstName 7 | { 8 | get 9 | { 10 | return firstName; 11 | } 12 | set 13 | { 14 | firstName = value; 15 | } 16 | } 17 | 18 | public string LastName { get; set; } = string.Empty; 19 | 20 | public int Id { get; private set; } 21 | 22 | public Staff() 23 | { 24 | FirstName = "Staff1"; 25 | } 26 | 27 | public void CalculateFees(decimal electiveFees, ref decimal roughFees, 28 | out decimal finalFees) 29 | { 30 | electiveFees = 10000; 31 | roughFees = 10000; 32 | finalFees = 10000; 33 | } 34 | 35 | // public void UpdateInfo(string firstName) 36 | // { 37 | // FirstName = firstName; 38 | // } 39 | 40 | public void UpdateInfo(string firstName, string lastName = "") 41 | { 42 | FirstName = firstName; 43 | LastName = lastName; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Section05-Interface/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student : IStudent 6 | { 7 | // Class fields 8 | public string FirstName { get ; set; } 9 | public string LastName { get ; set; } 10 | 11 | public int StudentId = 10000; 12 | 13 | // readonly field 14 | public readonly int MaxEnrolledCourses = 3; 15 | 16 | // Static field 17 | public static int MaxBooksAllowed = 6; 18 | 19 | 20 | // Student constructor 21 | public Student() 22 | { 23 | Console.WriteLine("Calling Student.Student()"); 24 | 25 | // All initializations goes here. 26 | int TotalCourses = 6; 27 | MaxEnrolledCourses = TotalCourses; 28 | } 29 | 30 | public Student(int id, string firstName, string lastName) 31 | { 32 | Console.WriteLine("Calling Student.Student(int, string, string)"); 33 | 34 | StudentId = id; 35 | FirstName = firstName; 36 | LastName = lastName; 37 | } 38 | 39 | ~Student() 40 | { 41 | // Cleanup code goes here. 42 | } 43 | 44 | public int GetId() 45 | { 46 | return StudentId; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CMS.UI.Display; 3 | using CMS.UI.Models; 4 | 5 | namespace CMS.Application 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | ICourse csCourse = new CSCourse(); 12 | ICourse eleCourse = new ElectronicsCourse(); 13 | 14 | Console.WriteLine(csCourse.GetTotalElectives()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class CSCourse : ICourse 6 | { 7 | public int TotalDurationInDays { get; set; } 8 | public List Subjects => throw new System.NotImplementedException(); 9 | 10 | public void AddSubject(CourseSubject subject) 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | 15 | public void AddSubject(List subjectsList) 16 | { 17 | throw new System.NotImplementedException(); 18 | } 19 | 20 | public void RemoveSubject(CourseSubject subject) 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = null; 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public void AddSubject(CourseSubject subject) 22 | { 23 | subjects.Add(subject); 24 | } 25 | 26 | public void RemoveSubject(CourseSubject subject) 27 | { 28 | subjects.Remove(subject); 29 | } 30 | 31 | public void AddSubject(List subjectsList) 32 | { 33 | subjects.AddRange(subjectsList); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class ElectronicsCourse : ICourse 6 | { 7 | List ICourse.Subjects => throw new System.NotImplementedException(); 8 | 9 | int ICourse.TotalDurationInDays { get => throw new System.NotImplementedException(); 10 | set => throw new System.NotImplementedException(); } 11 | 12 | void ICourse.AddSubject(CourseSubject subject) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | 17 | void ICourse.AddSubject(List subjectsList) 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | 22 | void ICourse.RemoveSubject(CourseSubject subject) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string GetFullName(); 6 | } 7 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | private string firstName; 6 | public string FirstName 7 | { 8 | get 9 | { 10 | return firstName; 11 | } 12 | set 13 | { 14 | firstName = value; 15 | } 16 | } 17 | 18 | public string LastName { get; set; } = string.Empty; 19 | 20 | public int Id { get; private set; } 21 | 22 | public Staff() 23 | { 24 | FirstName = "Staff1"; 25 | } 26 | 27 | public void CalculateFees(decimal electiveFees, ref decimal roughFees, 28 | out decimal finalFees) 29 | { 30 | electiveFees = 10000; 31 | roughFees = 10000; 32 | finalFees = 10000; 33 | } 34 | 35 | // public void UpdateInfo(string firstName) 36 | // { 37 | // FirstName = firstName; 38 | // } 39 | 40 | public void UpdateInfo(string firstName, string lastName = "") 41 | { 42 | FirstName = firstName; 43 | LastName = lastName; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Section05-Interface/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Student 6 | { 7 | // Class fields 8 | public string FirstName = default; 9 | public string LastName = string.Empty; 10 | public int StudentId = 10000; 11 | 12 | // readonly field 13 | public readonly int MaxEnrolledCourses = 3; 14 | 15 | // Static field 16 | public static int MaxBooksAllowed = 6; 17 | 18 | // Student constructor 19 | public Student() 20 | { 21 | Console.WriteLine("Calling Student.Student()"); 22 | 23 | // All initializations goes here. 24 | int TotalCourses = 6; 25 | MaxEnrolledCourses = TotalCourses; 26 | } 27 | 28 | public Student(int id, string firstName, string lastName) 29 | { 30 | Console.WriteLine("Calling Student.Student(int, string, string)"); 31 | 32 | StudentId = id; 33 | FirstName = firstName; 34 | LastName = lastName; 35 | } 36 | 37 | ~Student() 38 | { 39 | // Cleanup code goes here. 40 | 41 | } 42 | 43 | public int GetId() 44 | { 45 | return StudentId; 46 | } 47 | 48 | public string GetFullName() 49 | { 50 | return $"{FirstName} {LastName}"; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | For the Staff class, do the following: 3 | 1. Make it derive from the Person class and remove the properties from the Staff class that is already defined in the Person class. 4 | 5 | 2. Add WorkingHoursPerWeek as an additional property to the Staff class. 6 | 7 | 3. Add Staff(string firstName, string LastName) constructor and pass the values to the corresponding Person class constructor. Also, assign 40 hours to the WorkingHoursPerWeek property in this constructor. 8 | 9 | 4. Add appropriate access modifier to the CalculateFees method so that it is accessible by any derived type of Staff class. Similarly, make the UpdateInfo method to be accessible by any derived type of Staff class, but within CMS.UI.Display assembly only. 10 | 11 | 5. In the console application, CMS.Application, create an instance of Staff class initializing with “Mary Smith” name and assign it to Person instance person2. Next, print its WorkingHoursPerWeek value to the console only if person2 is of type Staff. 12 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CMS.UI.Display; 4 | using CMS.UI.Models; 5 | 6 | namespace CMS.Application 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Student student = new Student(); 13 | student.GetFullName(); 14 | List hobbies = student.Hobbies; 15 | 16 | Student student1 = new Student(10001, "Robert", "Smith"); 17 | Console.WriteLine(student1.GetFullName()); 18 | 19 | Console.WriteLine("Casting in Inheritance"); 20 | Person person = new Student(10001, "David", "Smith"); 21 | Console.WriteLine(person.GetFullName()); 22 | 23 | Student student2 = person as Student; 24 | if (student2 != null) 25 | { 26 | List lstHobbies = student2.Hobbies; 27 | } 28 | 29 | if(person is Student) 30 | { 31 | // Refer Student members here. 32 | Student student3 = person as Student; 33 | List lstHobbies = student3.Hobbies; 34 | } 35 | 36 | // Assignment1 Solution 37 | Person person2 = new Staff("Mary", "Smith"); 38 | if(person2 is Staff) 39 | { 40 | Staff staff = person2 as Staff; 41 | Console.WriteLine(staff.WorkingHoursPerWeek); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | netcoreapp3.1 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Display/Contractor.cs: -------------------------------------------------------------------------------- 1 | using CMS.UI.Models; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public class Contractor : Person 6 | { 7 | public string GetFirstName() 8 | { 9 | return FirstName; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class CSCourse : ICourse 6 | { 7 | public int TotalDurationInDays { get; set; } 8 | public List Subjects => throw new System.NotImplementedException(); 9 | 10 | public void AddSubject(CourseSubject subject) 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | 15 | public void AddSubject(List subjectsList) 16 | { 17 | throw new System.NotImplementedException(); 18 | } 19 | 20 | public void RemoveSubject(CourseSubject subject) 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Contracts/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Contracts/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | static int MaxBooksAllowed = 6; 8 | 9 | string GetFullName() 10 | { 11 | return $"{FirstName} {LastName}"; 12 | } 13 | static string WhoAmI() 14 | { 15 | return "Student"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = null; 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public void AddSubject(CourseSubject subject) 22 | { 23 | subjects.Add(subject); 24 | } 25 | 26 | public void RemoveSubject(CourseSubject subject) 27 | { 28 | subjects.Remove(subject); 29 | } 30 | 31 | public void AddSubject(List subjectsList) 32 | { 33 | subjects.AddRange(subjectsList); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class ElectronicsCourse : ICourse 6 | { 7 | List ICourse.Subjects => throw new System.NotImplementedException(); 8 | 9 | int ICourse.TotalDurationInDays { get => throw new System.NotImplementedException(); 10 | set => throw new System.NotImplementedException(); } 11 | 12 | void ICourse.AddSubject(CourseSubject subject) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | 17 | void ICourse.AddSubject(List subjectsList) 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | 22 | void ICourse.RemoveSubject(CourseSubject subject) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Person 6 | { 7 | public Person() 8 | { 9 | Console.WriteLine("Calling Person.Person()"); 10 | } 11 | 12 | public Person(string firstName, string lastName) 13 | { 14 | Console.WriteLine("Calling Person.Person(string, string)"); 15 | 16 | this.FirstName = firstName; 17 | this.LastName = lastName; 18 | } 19 | 20 | protected internal string FirstName { get; set; } 21 | public string LastName { get; set; } 22 | public virtual string GetFullName() 23 | { 24 | return $"{FirstName} {LastName}"; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff : Person 4 | { 5 | public int Id { get; private set; } 6 | 7 | public int WorkingHoursPerWeek { get; set; } 8 | 9 | public Staff() 10 | { 11 | FirstName = "Staff1"; 12 | } 13 | 14 | public Staff(string firstName, string lastName) 15 | : base(firstName, lastName) 16 | { 17 | // Staff class initializations go here. 18 | WorkingHoursPerWeek = 40; 19 | } 20 | 21 | protected void CalculateFees(decimal electiveFees, ref decimal roughFees, 22 | out decimal finalFees) 23 | { 24 | electiveFees = 10000; 25 | roughFees = 10000; 26 | finalFees = 10000; 27 | } 28 | 29 | // public void UpdateInfo(string firstName) 30 | // { 31 | // FirstName = firstName; 32 | // } 33 | 34 | private protected void UpdateInfo(string firstName, string lastName = "") 35 | { 36 | FirstName = firstName; 37 | LastName = lastName; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Section06-Inheritance/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Student : Person 7 | { 8 | public List Hobbies { get; set; } 9 | public int StudentId = 10000; 10 | 11 | // readonly field 12 | public readonly int MaxEnrolledCourses = 3; 13 | 14 | // Static field 15 | public static int MaxBooksAllowed = 6; 16 | 17 | 18 | // Student constructor 19 | public Student() 20 | { 21 | Console.WriteLine("Calling Student.Student()"); 22 | 23 | // All initializations goes here. 24 | int TotalCourses = 6; 25 | MaxEnrolledCourses = TotalCourses; 26 | } 27 | 28 | public Student(int id, string firstName, string lastName) 29 | : base(firstName, lastName) 30 | { 31 | Console.WriteLine("Calling Student.Student(int, string, string)"); 32 | 33 | StudentId = id; 34 | FirstName = firstName; 35 | LastName = lastName; 36 | } 37 | 38 | ~Student() 39 | { 40 | // Cleanup code goes here. 41 | } 42 | 43 | public int GetId() 44 | { 45 | return StudentId; 46 | } 47 | 48 | public string GetFirstName() 49 | { 50 | return FirstName; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CMS.UI.Display; 4 | using CMS.UI.Models; 5 | 6 | namespace CMS.Application 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Student student = new Student(); 13 | student.GetFullName(); 14 | List hobbies = student.Hobbies; 15 | 16 | Student student1 = new Student(10001, "Robert", "Smith"); 17 | Console.WriteLine(student1.GetFullName()); 18 | 19 | Console.WriteLine("Casting in Inheritance"); 20 | Person person = new Student(10001, "David", "Smith"); 21 | Console.WriteLine(person.GetFullName()); 22 | 23 | Student student2 = person as Student; 24 | if (student2 != null) 25 | { 26 | List lstHobbies = student2.Hobbies; 27 | } 28 | 29 | if(person is Student) 30 | { 31 | // Refer Student members here. 32 | Student student3 = person as Student; 33 | List lstHobbies = student3.Hobbies; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | netcoreapp3.1 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Display/Contractor.cs: -------------------------------------------------------------------------------- 1 | using CMS.UI.Models; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public class Contractor : Person 6 | { 7 | public string GetFirstName() 8 | { 9 | return FirstName; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class CSCourse : ICourse 6 | { 7 | public int TotalDurationInDays { get; set; } 8 | public List Subjects => throw new System.NotImplementedException(); 9 | 10 | public void AddSubject(CourseSubject subject) 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | 15 | public void AddSubject(List subjectsList) 16 | { 17 | throw new System.NotImplementedException(); 18 | } 19 | 20 | public void RemoveSubject(CourseSubject subject) 21 | { 22 | throw new System.NotImplementedException(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Contracts/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Contracts/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | static int MaxBooksAllowed = 6; 8 | 9 | string GetFullName() 10 | { 11 | return $"{FirstName} {LastName}"; 12 | } 13 | static string WhoAmI() 14 | { 15 | return "Student"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = null; 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public void AddSubject(CourseSubject subject) 22 | { 23 | subjects.Add(subject); 24 | } 25 | 26 | public void RemoveSubject(CourseSubject subject) 27 | { 28 | subjects.Remove(subject); 29 | } 30 | 31 | public void AddSubject(List subjectsList) 32 | { 33 | subjects.AddRange(subjectsList); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | } 8 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class ElectronicsCourse : ICourse 6 | { 7 | List ICourse.Subjects => throw new System.NotImplementedException(); 8 | 9 | int ICourse.TotalDurationInDays { get => throw new System.NotImplementedException(); 10 | set => throw new System.NotImplementedException(); } 11 | 12 | void ICourse.AddSubject(CourseSubject subject) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | 17 | void ICourse.AddSubject(List subjectsList) 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | 22 | void ICourse.RemoveSubject(CourseSubject subject) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Person 6 | { 7 | public Person() 8 | { 9 | Console.WriteLine("Calling Person.Person()"); 10 | } 11 | 12 | public Person(string firstName, string lastName) 13 | { 14 | Console.WriteLine("Calling Person.Person(string, string)"); 15 | 16 | this.FirstName = firstName; 17 | this.LastName = lastName; 18 | } 19 | 20 | protected internal string FirstName { get; set; } 21 | public string LastName { get; set; } 22 | public virtual string GetFullName() 23 | { 24 | return $"{FirstName} {LastName}"; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff 4 | { 5 | private string firstName; 6 | public string FirstName 7 | { 8 | get 9 | { 10 | return firstName; 11 | } 12 | set 13 | { 14 | firstName = value; 15 | } 16 | } 17 | 18 | public string LastName { get; set; } = string.Empty; 19 | 20 | public int Id { get; private set; } 21 | 22 | public Staff() 23 | { 24 | FirstName = "Staff1"; 25 | } 26 | 27 | public void CalculateFees(decimal electiveFees, ref decimal roughFees, 28 | out decimal finalFees) 29 | { 30 | electiveFees = 10000; 31 | roughFees = 10000; 32 | finalFees = 10000; 33 | } 34 | 35 | // public void UpdateInfo(string firstName) 36 | // { 37 | // FirstName = firstName; 38 | // } 39 | 40 | public void UpdateInfo(string firstName, string lastName = "") 41 | { 42 | FirstName = firstName; 43 | LastName = lastName; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Section06-Inheritance/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Student : Person 7 | { 8 | public List Hobbies { get; set; } 9 | public int StudentId = 10000; 10 | 11 | // readonly field 12 | public readonly int MaxEnrolledCourses = 3; 13 | 14 | // Static field 15 | public static int MaxBooksAllowed = 6; 16 | 17 | 18 | // Student constructor 19 | public Student() 20 | { 21 | Console.WriteLine("Calling Student.Student()"); 22 | 23 | // All initializations goes here. 24 | int TotalCourses = 6; 25 | MaxEnrolledCourses = TotalCourses; 26 | } 27 | 28 | public Student(int id, string firstName, string lastName) 29 | : base(firstName, lastName) 30 | { 31 | Console.WriteLine("Calling Student.Student(int, string, string)"); 32 | 33 | StudentId = id; 34 | FirstName = firstName; 35 | LastName = lastName; 36 | } 37 | 38 | ~Student() 39 | { 40 | // Cleanup code goes here. 41 | } 42 | 43 | public int GetId() 44 | { 45 | return StudentId; 46 | } 47 | 48 | public string GetFirstName() 49 | { 50 | return FirstName; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1.md: -------------------------------------------------------------------------------- 1 | # Problem Statements 2 | For the ElectronicsCourse class, do the following: 3 | 1. Make it derive from the Course class and remove the members from it that are already defined in the Course class. 4 | 5 | 2. Add the AddSubject method that hides the corresponding implementation from the Course class. 6 | 7 | 3. Add virtual to the RemoveSubject method in Course class and override the same in the ElectronicsCourse class. 8 | 9 | 4. Create electronicsCourse instance for ElectronicsCourse class in the console application. Call AddSubject with a new course subject instance with id as 401 and subjectName as “Basics of Electrical Science”. Then call RemoveSubject method to remove the previously added course subject. Run the program and check whether the appropriate method from a base class or derived class gets triggered. 10 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CMS.UI.Display; 4 | using CMS.UI.Models; 5 | 6 | namespace CMS.Application 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Course course = new CSCourse(); 13 | course.AddSubject(new CourseSubject(301, "Programming")); 14 | 15 | Course electronicsCourse = new ElectronicsCourse(); 16 | CourseSubject subject = new CourseSubject(401, "Basics of Electrical Science"); 17 | electronicsCourse.AddSubject(subject); 18 | electronicsCourse.RemoveSubject(subject); 19 | 20 | // Expected output. 21 | // Calling CSCourse.AddSubject(CourseSubject) 22 | // Calling Course.AddSubject(CourseSubject) 23 | // Calling ElectronicsCourse.RemoveSubject(CourseSubject) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | netcoreapp3.1 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Display/Contractor.cs: -------------------------------------------------------------------------------- 1 | using CMS.UI.Models; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public class Contractor : Person 6 | { 7 | public string GetFirstName() 8 | { 9 | return FirstName; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class CSCourse : Course 7 | { 8 | public sealed override void AddSubject(CourseSubject subject) 9 | { 10 | Console.WriteLine("Calling CSCourse.AddSubject(CourseSubject)"); 11 | 12 | // Custom business logic go here. 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Contracts/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Contracts/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | static int MaxBooksAllowed = 6; 8 | 9 | string GetFullName() 10 | { 11 | return $"{FirstName} {LastName}"; 12 | } 13 | static string WhoAmI() 14 | { 15 | return "Student"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = new List(); 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public virtual void AddSubject(CourseSubject subject) 22 | { 23 | Console.WriteLine("Calling Course.AddSubject(CourseSubject)"); 24 | 25 | subjects.Add(subject); 26 | } 27 | 28 | public virtual void RemoveSubject(CourseSubject subject) 29 | { 30 | subjects.Remove(subject); 31 | } 32 | 33 | public void AddSubject(List subjectsList) 34 | { 35 | subjects.AddRange(subjectsList); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | public CourseSubject(int id, string subjectName) 8 | { 9 | this.Id = id; 10 | this.SubjectName = subjectName; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class ElectronicsCourse : Course 7 | { 8 | public new void AddSubject(CourseSubject subject) 9 | { 10 | Console.WriteLine("Calling ElectronicsCourse.AddSubject(CourseSubject)"); 11 | 12 | // Custom business logic go here. 13 | 14 | return; 15 | } 16 | 17 | public override void RemoveSubject(CourseSubject subject) 18 | { 19 | Console.WriteLine("Calling ElectronicsCourse.RemoveSubject(CourseSubject)"); 20 | 21 | // Custom business logic go here. 22 | 23 | return; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Hobby.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public abstract class Hobby 4 | { 5 | private string name; 6 | public string GetHobbyName() 7 | { 8 | return name; 9 | } 10 | 11 | public abstract string GetTypeOfHobby(); 12 | 13 | public void Initiaze(string hobbyName) 14 | { 15 | name = hobbyName; 16 | } 17 | } 18 | 19 | public class PhotographyHobby : Hobby 20 | { 21 | public override string GetTypeOfHobby() 22 | { 23 | throw new System.NotImplementedException(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Person 6 | { 7 | public Person() 8 | { 9 | Console.WriteLine("Calling Person.Person()"); 10 | } 11 | 12 | public Person(string firstName, string lastName) 13 | { 14 | Console.WriteLine("Calling Person.Person(string, string)"); 15 | 16 | this.FirstName = firstName; 17 | this.LastName = lastName; 18 | } 19 | 20 | protected internal string FirstName { get; set; } 21 | public string LastName { get; set; } 22 | public virtual string GetFullName() 23 | { 24 | return $"{FirstName} {LastName}"; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff : Person 4 | { 5 | public int Id { get; private set; } 6 | 7 | public int WorkingHoursPerWeek { get; set; } 8 | 9 | public Staff() 10 | { 11 | FirstName = "Staff1"; 12 | } 13 | 14 | public Staff(string firstName, string lastName) 15 | : base(firstName, lastName) 16 | { 17 | // Staff class initializations go here. 18 | WorkingHoursPerWeek = 40; 19 | } 20 | 21 | protected void CalculateFees(decimal electiveFees, ref decimal roughFees, 22 | out decimal finalFees) 23 | { 24 | electiveFees = 10000; 25 | roughFees = 10000; 26 | finalFees = 10000; 27 | } 28 | 29 | // public void UpdateInfo(string firstName) 30 | // { 31 | // FirstName = firstName; 32 | // } 33 | 34 | private protected void UpdateInfo(string firstName, string lastName = "") 35 | { 36 | FirstName = firstName; 37 | LastName = lastName; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/Assignment1Solution/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Student : Person 7 | { 8 | public List Hobbies { get; set; } 9 | public int StudentId = 10000; 10 | 11 | // readonly field 12 | public readonly int MaxEnrolledCourses = 3; 13 | 14 | // Static field 15 | public static int MaxBooksAllowed = 6; 16 | 17 | 18 | // Student constructor 19 | public Student() 20 | { 21 | Console.WriteLine("Calling Student.Student()"); 22 | 23 | // All initializations goes here. 24 | int TotalCourses = 6; 25 | MaxEnrolledCourses = TotalCourses; 26 | } 27 | 28 | public Student(int id, string firstName, string lastName) 29 | : base(firstName, lastName) 30 | { 31 | Console.WriteLine("Calling Student.Student(int, string, string)"); 32 | 33 | StudentId = id; 34 | FirstName = firstName; 35 | LastName = lastName; 36 | } 37 | 38 | ~Student() 39 | { 40 | // Cleanup code goes here. 41 | } 42 | 43 | public int GetId() 44 | { 45 | return StudentId; 46 | } 47 | 48 | public string GetFirstName() 49 | { 50 | return FirstName; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.Application/CMS.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Exe 10 | netcoreapp3.1 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.Application/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using CMS.UI.Display; 4 | using CMS.UI.Models; 5 | 6 | namespace CMS.Application 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | Course course = new CSCourse(); 13 | course.AddSubject(new CourseSubject(301, "Programming")); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Display/CMS.UI.Display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | netcoreapp3.1 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Display/Contractor.cs: -------------------------------------------------------------------------------- 1 | using CMS.UI.Models; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public class Contractor : Person 6 | { 7 | public string GetFirstName() 8 | { 9 | return FirstName; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Display/Display.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Display 4 | { 5 | public static class Display 6 | { 7 | public static void Show(string strMessage) 8 | { 9 | Console.WriteLine(strMessage); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/CMS.UI.Models.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/CSCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class CSCourse : Course 7 | { 8 | public sealed override void AddSubject(CourseSubject subject) 9 | { 10 | Console.WriteLine("Calling CSCourse.AddSubject(CourseSubject)"); 11 | 12 | // Custom business logic go here. 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Contracts/ICourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public interface ICourse 6 | { 7 | static int DefaultElectives = 8; 8 | 9 | static void ShowDetails() 10 | { 11 | // details go here. 12 | } 13 | 14 | int TotalDurationInDays { get; set; } 15 | int TotalSubjects 16 | { 17 | get 18 | { 19 | return Subjects.Count; 20 | } 21 | } 22 | List Subjects { get; } 23 | 24 | void AddSubject(CourseSubject subject); 25 | void AddSubject(List subjectsList); 26 | void RemoveSubject(CourseSubject subject); 27 | int GetTotalElectives() 28 | { 29 | return 0; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Contracts/IStudent.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public interface IStudent 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | static int MaxBooksAllowed = 6; 8 | 9 | string GetFullName() 10 | { 11 | return $"{FirstName} {LastName}"; 12 | } 13 | static string WhoAmI() 14 | { 15 | return "Student"; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Course.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Course : ICourse 7 | { 8 | public int CourseId; 9 | public string CourseName; 10 | public static int MaxSubjects = 8; 11 | public int TotalDurationInDays { get; set; } 12 | 13 | private List subjects = new List(); 14 | 15 | public List Subjects 16 | { 17 | get { return subjects; } 18 | private set { subjects = value; } 19 | } 20 | 21 | public virtual void AddSubject(CourseSubject subject) 22 | { 23 | Console.WriteLine("Calling Course.AddSubject(CourseSubject)"); 24 | 25 | subjects.Add(subject); 26 | } 27 | 28 | public void RemoveSubject(CourseSubject subject) 29 | { 30 | subjects.Remove(subject); 31 | } 32 | 33 | public void AddSubject(List subjectsList) 34 | { 35 | subjects.AddRange(subjectsList); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/CourseSubject.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class CourseSubject 4 | { 5 | public int Id; 6 | public string SubjectName; 7 | public CourseSubject(int id, string subjectName) 8 | { 9 | this.Id = id; 10 | this.SubjectName = subjectName; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/ElectronicsCourse.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class ElectronicsCourse : ICourse 6 | { 7 | List ICourse.Subjects => throw new System.NotImplementedException(); 8 | 9 | int ICourse.TotalDurationInDays { get => throw new System.NotImplementedException(); 10 | set => throw new System.NotImplementedException(); } 11 | 12 | void ICourse.AddSubject(CourseSubject subject) 13 | { 14 | throw new System.NotImplementedException(); 15 | } 16 | 17 | void ICourse.AddSubject(List subjectsList) 18 | { 19 | throw new System.NotImplementedException(); 20 | } 21 | 22 | void ICourse.RemoveSubject(CourseSubject subject) 23 | { 24 | throw new System.NotImplementedException(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Hobby.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public abstract class Hobby 4 | { 5 | private string name; 6 | public string GetHobbyName() 7 | { 8 | return name; 9 | } 10 | 11 | public abstract string GetTypeOfHobby(); 12 | 13 | public void Initiaze(string hobbyName) 14 | { 15 | name = hobbyName; 16 | } 17 | } 18 | 19 | public class PhotographyHobby : Hobby 20 | { 21 | public override string GetTypeOfHobby() 22 | { 23 | throw new System.NotImplementedException(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CMS.UI.Models 4 | { 5 | public class Person 6 | { 7 | public Person() 8 | { 9 | Console.WriteLine("Calling Person.Person()"); 10 | } 11 | 12 | public Person(string firstName, string lastName) 13 | { 14 | Console.WriteLine("Calling Person.Person(string, string)"); 15 | 16 | this.FirstName = firstName; 17 | this.LastName = lastName; 18 | } 19 | 20 | protected internal string FirstName { get; set; } 21 | public string LastName { get; set; } 22 | public virtual string GetFullName() 23 | { 24 | return $"{FirstName} {LastName}"; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Staff.cs: -------------------------------------------------------------------------------- 1 | namespace CMS.UI.Models 2 | { 3 | public class Staff : Person 4 | { 5 | public int Id { get; private set; } 6 | 7 | public int WorkingHoursPerWeek { get; set; } 8 | 9 | public Staff() 10 | { 11 | FirstName = "Staff1"; 12 | } 13 | 14 | public Staff(string firstName, string lastName) 15 | : base(firstName, lastName) 16 | { 17 | // Staff class initializations go here. 18 | WorkingHoursPerWeek = 40; 19 | } 20 | 21 | protected void CalculateFees(decimal electiveFees, ref decimal roughFees, 22 | out decimal finalFees) 23 | { 24 | electiveFees = 10000; 25 | roughFees = 10000; 26 | finalFees = 10000; 27 | } 28 | 29 | // public void UpdateInfo(string firstName) 30 | // { 31 | // FirstName = firstName; 32 | // } 33 | 34 | private protected void UpdateInfo(string firstName, string lastName = "") 35 | { 36 | FirstName = firstName; 37 | LastName = lastName; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Section07-Polymorphism/CMS/CMS.UI.Models/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CMS.UI.Models 5 | { 6 | public class Student : Person 7 | { 8 | public List Hobbies { get; set; } 9 | public int StudentId = 10000; 10 | 11 | // readonly field 12 | public readonly int MaxEnrolledCourses = 3; 13 | 14 | // Static field 15 | public static int MaxBooksAllowed = 6; 16 | 17 | 18 | // Student constructor 19 | public Student() 20 | { 21 | Console.WriteLine("Calling Student.Student()"); 22 | 23 | // All initializations goes here. 24 | int TotalCourses = 6; 25 | MaxEnrolledCourses = TotalCourses; 26 | } 27 | 28 | public Student(int id, string firstName, string lastName) 29 | : base(firstName, lastName) 30 | { 31 | Console.WriteLine("Calling Student.Student(int, string, string)"); 32 | 33 | StudentId = id; 34 | FirstName = firstName; 35 | LastName = lastName; 36 | } 37 | 38 | ~Student() 39 | { 40 | // Cleanup code goes here. 41 | } 42 | 43 | public int GetId() 44 | { 45 | return StudentId; 46 | } 47 | 48 | public string GetFirstName() 49 | { 50 | return FirstName; 51 | } 52 | } 53 | } 54 | --------------------------------------------------------------------------------