locked
NumericUpDown() RRS feed

  • Question

  • I have a windows form and i have declared an object of NumericUpDown()

     this._nudHeight = new System.Windows.Forms.NumericUpDown();

    can you explain me the meaning of code given below, according to it 10,000 is the max. val and 0 is the min val,  but what other two zeros represent?

     this._nudHeight.Maximum = new decimal(new int[] {
                10000,
                0,
                0,
                0});

    Tuesday, July 16, 2013 8:55 AM

Answers

  • Well, all the 3 zeros are part of the 10,000.

    The Int array is actually represent a bits array.

    if you will put a huge number like 429495642333333 you will get in the

    InitializeComponent method:

    this.numericUpDown1.Maximum = new decimal(new int[] {
                -1087266667,
                99999,
                0,
                0});

    I am not an expert in the all the bit to Dec, hex, etc... converting stuff, but you will find more info in the next link:

    http://msdn.microsoft.com/en-us/library/system.decimal.getbits.aspx

    • Proposed as answer by Wizend Tuesday, July 16, 2013 10:58 AM
    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:56 AM
    Tuesday, July 16, 2013 10:05 AM
  • Additional you might read up the C# Reference entry regarding the decimal constructor you are using:

    http://msdn.microsoft.com/en-us/library/t1de0ya1.aspx

    wizend

    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:59 AM
    Tuesday, July 16, 2013 10:59 AM
  • Well, that is one really wierd and complicated way to set a decimal ;)

    I would just write:

    this._nudHeight.Maximum = 10000m;

    and for 429495642333333 I would jsut write:

    this._nudHeight.Maximum = 429495642333333m;

    the suffix 'm' tells the compiler "this is not a double or int, this is a decimal". I guess if you really want to deal with how decimal works internally, you can use the Constructor that expects a one dimensional, 4 Element Int Array. Or the 3 Int32, Boolean & Byte Version. But most people use just a string literal with m as suffix:

    http://msdn.microsoft.com/en-us/library/364x0z75.aspx

    The core thing is, that internally it Decimal uses a 96-bit integer. You can't use 96-bit integers (or could not when this class was written), but if you know how do it you can split one 96-bit Number over 3 32-bit Numbers.

    Elements 1-3 of the Array[] Verion do the same as the 3 Int32 in the complicated version.
    Element 4 (index 3) of the array encodes what is done with the Boolean and Byte in the Complicated one.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


    • Edited by Christopher84 Tuesday, July 16, 2013 11:23 AM asdsas
    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:56 AM
    Tuesday, July 16, 2013 11:19 AM

All replies

  • Well, all the 3 zeros are part of the 10,000.

    The Int array is actually represent a bits array.

    if you will put a huge number like 429495642333333 you will get in the

    InitializeComponent method:

    this.numericUpDown1.Maximum = new decimal(new int[] {
                -1087266667,
                99999,
                0,
                0});

    I am not an expert in the all the bit to Dec, hex, etc... converting stuff, but you will find more info in the next link:

    http://msdn.microsoft.com/en-us/library/system.decimal.getbits.aspx

    • Proposed as answer by Wizend Tuesday, July 16, 2013 10:58 AM
    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:56 AM
    Tuesday, July 16, 2013 10:05 AM
  • Additional you might read up the C# Reference entry regarding the decimal constructor you are using:

    http://msdn.microsoft.com/en-us/library/t1de0ya1.aspx

    wizend

    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:59 AM
    Tuesday, July 16, 2013 10:59 AM
  • Well, that is one really wierd and complicated way to set a decimal ;)

    I would just write:

    this._nudHeight.Maximum = 10000m;

    and for 429495642333333 I would jsut write:

    this._nudHeight.Maximum = 429495642333333m;

    the suffix 'm' tells the compiler "this is not a double or int, this is a decimal". I guess if you really want to deal with how decimal works internally, you can use the Constructor that expects a one dimensional, 4 Element Int Array. Or the 3 Int32, Boolean & Byte Version. But most people use just a string literal with m as suffix:

    http://msdn.microsoft.com/en-us/library/364x0z75.aspx

    The core thing is, that internally it Decimal uses a 96-bit integer. You can't use 96-bit integers (or could not when this class was written), but if you know how do it you can split one 96-bit Number over 3 32-bit Numbers.

    Elements 1-3 of the Array[] Verion do the same as the 3 Int32 in the complicated version.
    Element 4 (index 3) of the array encodes what is done with the Boolean and Byte in the Complicated one.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


    • Edited by Christopher84 Tuesday, July 16, 2013 11:23 AM asdsas
    • Marked as answer by sakshi mittal Tuesday, July 16, 2013 11:56 AM
    Tuesday, July 16, 2013 11:19 AM