Solved

Question about Array.CreateInstance

Posted on 2014-09-18
2
52 Views
Last Modified: 2015-01-06
Below is an excerpt from a C#2012 book.
Question:
1. length specifies the size of the array to contain 6 elements, 2X3.  What is the lowerBoundsn for?
2.What is 0-baseed and 10-based referenced here?


The CreateInstance()method has many overloads to create multidimensional arrays and to create arrays
that are not 0-based. The following example creates a two-dimensional array with 2 X3 elements. The first
dimension is 1-based; the second dimension is 10-based:
int[] lengths = { 2, 3 };
int[] lowerBounds = { 1, 10 };
Array racers = Array.CreateInstance(typeof(Person), lengths, lowerBounds);

Thank you.
0
Comment
Question by:lapucca
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40331800
What is the lowerBoundsn for?
The starting index. Normally arrays are indexed from zero. When you change the lower bounds, you change at what index the array begins from.

What is 0-baseed and 10-based referenced here?
The author is just rephrasing that each array inside of racers starts at an index other than zero--the first starts at 1; the second from 10.

http://msdn.microsoft.com/en-us/library/x836773a(v=vs.110).aspx
0
 

Author Comment

by:lapucca
ID: 40360902
The length is 2x3 elements or 2 rows by 3 columns.  the pair of number for lower bound {1, 10}, indicates the racer array element can be access as below?
racer[1,10], racer[1,11], racer[1,12]
racer[2,10],racer[2,11], racer[2,12]

Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now