About arrays whose lower limit is not 0

Source: Internet
Author: User

Creation and testing of arrays whose lower limit is not 0:
Using system;
Using nunit. Framework;

[Testfixture]
Public class app
{
Static void main ()
{
App = new app ();
App. Run ();
}
 
[Test]
Public void run ()
{
Int [] lower = {3, 5}; // the lower threshold of one-dimensional start is 3, and the lower threshold of two-dimensional start is 5.
Int [] length = {2, 3}; // the length of one dimension is 2, and the length of two dimensions is 3.

// Create an array with a lower limit of not 0.
Decimal [,] dec = (decimal [,]) array. createinstance (typeof (decimal ),
Length, lower );

Assert. isnotnull (Dec, "DEC is null ");

// One-dimensional loop.
For (INT I = dec. getlowerbound (0); I <= dec. getupperbound (0); I ++)
{
// Two-dimensional loop
For (Int J = dec. getlowerbound (1); j <= dec. getupperbound (1); j ++)
{
// Assign a value.
Int [] val = new int [2] {I, j };
Dec. setvalue (decimal) (I * j), Val );

Console. writeline ("Dec [{0}, {1}] is: {2}", I, j, Dec [I, j]);
}
}

// Test
Assert. areequal (15 m, Dec [3, 5]);
Assert. areequal (28 m, Dec [4, 7]);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.