Advertisement
Guest User

Untitled

a guest
Feb 14th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace InheritanceAndPolymorphism
  6. {
  7. public class LocalCourse
  8. {
  9. public string Name { get; set; }
  10. public string TeacherName { get; set; }
  11. public IList<string> Students { get; set; }
  12. public string Lab { get; set; }
  13.  
  14. public LocalCourse(string name)
  15. {
  16. this.Name = name;
  17. this.TeacherName = null;
  18. this.Students = new List<string>();
  19. this.Lab = null;
  20. }
  21.  
  22. public LocalCourse(string courseName, string teacherName)
  23. {
  24. this.Name = courseName;
  25. this.TeacherName = teacherName;
  26. this.Students = new List<string>();
  27. this.Lab = null;
  28. }
  29.  
  30. public LocalCourse(string courseName, string teacherName, IList<string> students)
  31. {
  32. this.Name = courseName;
  33. this.TeacherName = teacherName;
  34. this.Students = students;
  35. this.Lab = null;
  36. }
  37.  
  38. private string GetStudentsAsString()
  39. {
  40. if (this.Students == null || this.Students.Count == 0)
  41. {
  42. return "{ }";
  43. }
  44. else
  45. {
  46. return "{ " + string.Join(", ", this.Students) + " }";
  47. }
  48. }
  49.  
  50. public override string ToString()
  51. {
  52. StringBuilder result = new StringBuilder();
  53. result.Append("LocalCourse { Name = ");
  54. result.Append(this.Name);
  55. if (this.TeacherName != null)
  56. {
  57. result.Append("; Teacher = ");
  58. result.Append(this.TeacherName);
  59. }
  60. result.Append("; Students = ");
  61. result.Append(this.GetStudentsAsString());
  62. if (this.Lab != null)
  63. {
  64. result.Append("; Lab = ");
  65. result.Append(this.Lab);
  66. }
  67. result.Append(" }");
  68. return result.ToString();
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement