Есть два класса. В главном записываем три значения ( name, course, grand ). Дальше передаем их в класс Student. Я хочу, чтобы значение course выводилось правильно после проверки свойства set на меньше нуля или больше пяти.
class Program
{
private static string name;
private static int course;
private static bool grand;
static void Main(string[] args)
{
name = Convert.ToString(Console.ReadLine());
course = Convert.ToInt32(Console.ReadLine());
grand = Convert.ToBoolean(Console.ReadLine());
Student Andrew = new Student(name, course, grand);
Console.WriteLine(Andrew.course);
Console.ReadLine();
}
}
class Student
{
private string name;
public int course;
private bool grand;
public int Course
{
set
{
if (value < 1)
{
course = 1;
}
else if (value > 5)
{
course = 5;
}
}
}
public Student(string name, int course, bool grand)
{
this.name = name;
this.course = course;
this.grand = grand;
print();
}
public void print()
{
Console.WriteLine(name);
Console.WriteLine(course);
Console.WriteLine(grand);
}
}
Student
вместоthis.course = course;
написатьCourse = course;
?