Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace InheritanceAndPolymorphism
- {
- abstract class Course
- {
- private string courseName;
- public string TeacherName { get; set; }
- private IList<string> students;
- public string CourseName
- {
- get
- {
- return this.courseName;
- }
- set
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- throw new ArgumentException("There is not any name of course entered.");
- }
- this.courseName = value;
- }
- }
- public IList<string> Students
- {
- get
- {
- return this.students;
- }
- set
- {
- if (value != null)
- {
- this.students = new List<string>();
- foreach (string student in value)
- {
- this.students.Add(student);
- }
- }
- else
- {
- this.students = null;
- }
- }
- }
- protected Course(string courseName, string teacherName, IList<string> students)
- {
- this.CourseName = courseName;
- this.TeacherName = teacherName;
- this.Students = students;
- }
- private string GetStudentsAsString()
- {
- if (this.Students == null || this.Students.Count == 0)
- {
- return "{ }";
- }
- else
- {
- return "{ " + string.Join(", ", this.Students) + " }";
- }
- }
- public override string ToString()
- {
- StringBuilder result = new StringBuilder();
- result.Append("LocalCourse { Name = ");
- result.Append(this.CourseName);
- if (this.TeacherName != null)
- {
- result.Append("; Teacher = ");
- result.Append(this.TeacherName);
- }
- result.Append("; Students = ");
- result.Append(this.GetStudentsAsString());
- return result.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement