Can array elements have different data types? Can someone please explain?
Can array elements have different data types? Can someone please explain?
Well, if we specified a type when declaring an array then we can't use multiple datatype for that array.
Check for an instance the below example ->
int[] arr = new int[5];
arr[0] = 9;
arr[1] = 45;
arr[2] = "66";
Then it gives Error as -> "Cannot implicitly convert type 'string' to 'int'";
Bookmarks