Свойство, не все ветви кода возвращают значения - C#
Формулировка задачи:
public class Point
{
int x;
int y;
public int Abcissa
{
set { x = value; }
get { return x; }
}
public int Ordinata
{
set { y = value; }
get { return y; }
}
//public Point(int x, int y)
//{
//}
public void vyvCoord()
{
Console.WriteLine("абцисса= " + x);
Console.WriteLine("ордината= " + y);
}
public void rasst()
{
Console.WriteLine("rasst ot (0;0)= " + Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)));
}
}
public class ColourPoint : Point
{
int coord;
public int Colour_Point
{
get
{
if ((Abcissa > 0) & (Ordinata > 0)) return (coord=1);
if ((Abcissa > 0) & (Ordinata < 0)) return (coord=4); // не все ветви кода возвращают значения
if ((Abcissa < 0) & (Ordinata < 0)) return (coord=3); // почему?
if ((Abcissa < 0) & (Ordinata > 0)) return (coord=2);
}
}
}
class Program
{
static void Main(string[] args)
{
string buf;
Console.WriteLine("Введите абциссу точки");
buf = Console.ReadLine();
int xx = Convert.ToInt32(buf);
string buf1;
Console.WriteLine("Введите ординату точки");
buf1 = Console.ReadLine();
int yy = Convert.ToInt32(buf1);
Point ob1 = new Point();
ob1.Abcissa = xx;
ob1.Ordinata = yy;
ob1.vyvCoord();
ob1.rasst();
ColourPoint ob2 = new ColourPoint();
Console.ReadLine();
}Решение задачи: «Свойство, не все ветви кода возвращают значения»
textual
Листинг программы
if ((Abcissa > 0) & (Ordinata > 0)) return (coord=1); if ((Abcissa > 0) & (Ordinata < 0)) return (coord=4); // не все ветви кода возвращают значения if ((Abcissa < 0) & (Ordinata < 0)) return (coord=3); // почему? if ((Abcissa < 0) & (Ordinata > 0)) return (coord=2);