Solved

Question about Array.CreateInstance

Posted on 2014-09-18
2
55 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reading excel file in .net 2 31
C# Linq - Join two objects into one 3 31
Updating a single record in forEach using C#/Entity 7 24
Header Font Size in Grid View 6 24
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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