An array of string objects that will hold 5 names would be declared using which statement?

0
85
guitar, music, acoustic guitar @ Pixabay

Declaring an array of string objects to hold 5 names is a fairly easy thing to do. There are many ways you can declare the array, but the most common way would be with which statement?

An array of string objects that will hold 5 names would be declared using the following syntax: var my string array = new string[n]; Then, you need to set the value of n: my string array.length = n;

textile, material, craft @ Pixabay

Finally, it is a good idea to initialize some values in your array (i.e., names) so that they are not undefined when you access them later on in your code as follows: for(int i=0; i <= n-l){ myStrings[i]=””; } //initialize first four strings with nulls or empty strings for(int j=0;j <= n-l+lb); myStrings[j]=strName[“Bob”];}//set last name at end of looping sequence once all five have been declared The array of string objects that will hold five names would be declared using the following syntax: var myStringArray = new string[n];.

This declaration is followed by setting the length of the object to n, which corresponds with how many strings you want in your array (i.e., my string array.length=n;).

Finally, it’s important to initialize some values so they are not undefined when accessing them later on – either nulls or empty strings work for this purpose (i.e., for(int i=0; i <= n-l){myStrings[i]=””;}//initialize first four strings with nulls or empty strings ). 

LEAVE A REPLY

Please enter your comment!
Please enter your name here