vendredi 17 avril 2020

C# If else with boolean condition

I was trying to toggle my _setting which initially is false so that I can return the message in the View() method. After tested, seems like the if-else statement inside the View() method doesn't work.. What should I fix it to get it works?

    private int _size;
    private string _brand;
    private bool _setting;

    public StorageDevice(string id, double price, Category category, int size, string brand):base(id, 
       price, category)
    {
        _size = size;
        _brand = brand;
        _setting = false;
    }

    public bool Setting 
    {
        get { return _setting; }
        set { _setting = value; }
    }

    public bool Format()
    {
        return _setting = !_setting;
    }

    public override string View()
    {
        if (_setting == true)
        {
            return "Size:" + _size + "/nBrand: " + _brand + "/nSetup Success!";
        }
        else
        {   return "Format needed!";}
    }

Aucun commentaire:

Enregistrer un commentaire