Работа return - C#
Формулировка задачи:
Объясните, пожалуйста, как в данных примерах работает return.
Листинг программы
- class Figure
- {
- /////////////
- public virtual bool Check(int x, int y)
- {
- return (x == y);
- }
- /////////////
- public bool BorderCheck(int Width, int Height)
- {
- if (this.x < 0)
- this.x = 0;
- if (this.y < 0)
- this.y = 0;
- if (this.x + this.Width > Width)
- this.x = Width - this.Width - 1;
- if (this.y + this.Height > Height)
- this.y = Height - this.Height - 1;
- return (this.x < 0 || this.x + this.Width > Width || this.y < 0 || this.y + this.Height > Height);
- }
- ////////
- }
- class Ellipse : Figure
- {
- /////
- public override bool Check(int x, int y)
- {
- float dx = this.x - x + this.Width / 2;
- float dy = this.y - y + this.Height / 2;
- return (dx * dx + dy * dy <= (Width * Width) / 4);
- }
- //////
- }
- class Rectangle: Figure
- {
- ////
- public override bool Check(int x, int y)
- {
- return (x > this.x && x < this.x + Width && y > this.y && y < this.y + Height);
- }
- /////
- }
Решение задачи: «Работа return»
textual
Листинг программы
- private void Form1_MouseClick(object sender, MouseEventArgs e)
- {
- for (int i = 0; i < list.GetLength(); i++)
- {
- if (list[i].Check(e.X - 20, e.Y - 20))
- {
- if (!list[i].mark)
- list[i].mark = true;
- else
- list[i].mark = false;
- Invalidate();
- return;
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д