I don't understand how this answer will not cause a compile or runtime problem. When is it okay to assign an array element to an array that has no subscript?
daa = daaa[0];
purpose of array with no subscript
Moderator: admin
-
- Posts: 4
- Joined: Sat Mar 22, 2014 11:33 am
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: purpose of array with no subscript
An assignment is ok only when the object you are assigning is of the same type as the type of the reference to which you are assigning.
So if daaa[0] refers to an array of the same dimensions as daa, then the assignment is ok. For example, if you have:
int[] ia = new int[]{ 1 };
int x = ia[0]; //here ia[0] and x are of same type i.e. int so it is ok.
int[][] iaa = new int[1][1]{ {1} };
ia = iaa[0]; here iaa is an array of array of ints but iaa[0] is an array of ints which is the same type as ia, so this is ok as well.
x = iaa[0]; this is not ok because x is not an array of ints, it is int.
HTH,
Paul.
So if daaa[0] refers to an array of the same dimensions as daa, then the assignment is ok. For example, if you have:
int[] ia = new int[]{ 1 };
int x = ia[0]; //here ia[0] and x are of same type i.e. int so it is ok.
int[][] iaa = new int[1][1]{ {1} };
ia = iaa[0]; here iaa is an array of array of ints but iaa[0] is an array of ints which is the same type as ia, so this is ok as well.
x = iaa[0]; this is not ok because x is not an array of ints, it is int.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Sat Mar 22, 2014 11:33 am
- Contact:
Re: purpose of array with no subscript
Thank you very much for the excellent explanation.
Who is online
Users browsing this forum: No registered users and 112 guests