H
H
Hipsana2020-06-01 01:20:12
C++ / C#
Hipsana, 2020-06-01 01:20:12

How to convert such a constructor in C#?

1 photo - what I originally had
2 photos - teacher's remark (what needs to be redone)
3 photo - how I redid this
4 photos - and these are the errors it gives (Impossible to assign a value to a property ...)

How to do it normally and why errors???5ed42d60e5a51248033055.png5ed42d69b415b361938469.png5ed42d77d7df3919040027.png5ed42d85bd529963604963.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eRKa, 2020-06-01
@Hipsana

ptivate int _num;
private int _den;

Drob(int num, int den)
{
    _num = num;
    _den = den;
}

public int Num
{
    get
    {
        return _num;
    }
}

public int Den
{
    get
    {
        return _den;
    }
}

public override strin ToString()
{
    ...
    _num = -_num;
    _den = Math.Abs(_den);
    ...
}

V
Vladimir Korotenko, 2020-06-01
@firedragon

public int Num
{
    get => _num; // а это новая форма записи, короче и красивей той что у вас
    set =>_num = value; // Присвоение значения собственно почему у вас и ругается, нет этого метода
}
public int NumSecond
{
    get => _sec; // а это новая форма записи, короче и красивей той что у вас
    private  set =>_sec = value; // А тут закрываете доступ извне
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question