What is wrong with the following statement? Dim strCities As String = {“Bombay”, “Chennai”, “Ladakh”, “Tamil Nadu”}

[amp_mcq option1=”static keyword missing” option2=”array elements should be initialized using single quotes” option3=”array elements should be in square brackets” option4=”array name should be strCities()” correct=”option3″]

The correct answer is: C. array elements should be in square brackets

The statement Dim strCities As String = {"Bombay", "Chennai", "Ladakh", "Tamil Nadu"} is trying to create an array of strings, but it is missing the square brackets [] that are required to specify the array elements. The correct statement would be:

Dim strCities As String() = {"Bombay", "Chennai", "Ladakh", "Tamil Nadu"}

Option A is incorrect because the static keyword is not required to declare an array. Option B is incorrect because string literals are always enclosed in double quotes. Option D is incorrect because the array name does not need to be enclosed in parentheses.

Exit mobile version