Going through my code, I was hoping to remove instances where I do this:
Height = new Unit(doubleValue);
where Height was representing a value in pixels.
I didn’t like having to say new everywhere, it felt like I should be able to just modify height’s value, but it is read-only.
As such, I stumbled upon Unit.Pixel() and Unit.Percentage(). The percentage method takes a double, but the pixel method only handles integers.
Is there some big reason behind this, an oversight, or a misunderstanding on my part?
Is it standard to create a new unit every time I wish to change height’s value?
EDIT: For reference,
The System.Web.UI.WebControls.Unit is a struct and therefore is immutable. You will need to create a new instance each time you want change the height value.
In web development, sizes are not always measured in pixels, there are many UnitTypes
I guess that the Constructor that accepts a double was provided for convenience.
You can do a simple test