Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:06:48+00:00 2026-05-23T19:06:48+00:00

Going through my code, I was hoping to remove instances where I do this:

  • 0

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,

Unit Constructor

Pixel Method

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:06:48+00:00Added an answer on May 23, 2026 at 7:06 pm

    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

    Unit.Pixel(int n) // Pixels are represented as integer values.
    

    I guess that the Constructor that accepts a double was provided for convenience.

    You can do a simple test

    var x = new Unit(5.0);
    var y = Unit.Pixel(5);
    
    Assert.AreEqual(x, y); // returns true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm going through old code (2.0) and I came across this: object isReviewingValue
I'm going through some new code I just wrote and adding NDoc sytle comments
I was going through some code at work and I found this inline FLAGS
I was going through some code and came across a scenario where my combobox
I was going through some code that I downloaded off the internet ( Got
I'm going through the source code of the less unix tool by Mark Nudelman,
I'm going through a Fortran code, and one bit has me a little puzzled.
Just going through the sample Scala code on Scala website, but encountered an annoying
I am going through some example assembly code for 16-bit real mode. I've come
I have been going through the core jQuery code and had a few why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.