Question

I am new to c# and mvc. I am using mvc. In view model, I have two property; one of them is public int MaxCapacity { get; set; } and the other one is public int UsedCapacity { get; set; } I want to use them and show UsedCapacity/MaxCapacity in the column but I don't know how to combine them. I want to cretae new property and write get set methods using MaxCapacity and UsedCapacity ;

public int Capacity
        {
            get
            {

            }
            set
            {

            }

        }
Was it helpful?

Solution

public int Capacity
    {
        get
        {
            return this.UsedCapacity/this.MaxCapacity;
        }
        set
        {
            if(value > MaxCapacity)
               throw new Exception("Can't set capacity bigger then max capacity");
            // Your code...
        }

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top