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...
}
}
Usage of C# get set methods
-
28-06-2022 - |
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
{
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow