Skip to content

Commit 0c40a45

Browse files
Gnbrkm41jkotasThraka
authored
Update Array.CreateInstance docs to mention language support of non-zero based arrays (#3338)
* Update Array's docs to mention language support * Non-zero based arrays are not supported in all major languages (C#, VB, F# etc...). This commit adds a note to the System.Array.CreateInstance(System.Type,System.Int32[],System.Int32[]) to mention that not all languages support non-zero based arrays with a brief C# example. #901 * Apply suggestions from code review Co-Authored-By: Andy De George <[email protected]> Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: Andy De George <[email protected]>
1 parent 771bd48 commit 0c40a45

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

xml/System/Array.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,8 +2516,9 @@
25162516

25172517
This method is an O(`n`) operation, where `n` is the product of all values in `lengths`.
25182518

2519-
2520-
2519+
> [!NOTE]
2520+
> Not all languages support arrays with non-zero lower bounds, and therefore you may not be able to cast instances of non-zero based <xref:System.Array> to the language's array type. For example, you cannot cast a 1-dimensional integer array with the lower bound 6 to C#'s `int[]` type. This results in <xref:System.InvalidCastException> during runtime with the message "Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'.", where the asterisk (*) means non-zero based index. However, you can cast zero based arrays of any rank created with <xref:System.Array.CreateInstance(System.Type,System.Int32[],System.Int32[])> to the language's array. For example, you can cast a 2-dimensional zero based integer array created with this method to C#'s `int[,]` type.
2521+
25212522
## Examples
25222523
The following code example shows how to create and initialize a multidimensional <xref:System.Array> with specified lower bounds.
25232524

0 commit comments

Comments
 (0)